Port positioning project development notes 3 · Web page based on JSP implementation

Port positioning project development notes 3 · Web page based on JSP implementation


I completed the realization of the real-time location acquisition function of the WeChat applet in the first two times. This time, we need to develop the function of data interaction with the WeChat applet on the web side. I haven't been in Java for many years, and now I suddenly feel a little familiar and strange.

Get data of WeChat applet in java background

We have made a simple button on the WeChat applet, and click to trigger the postdata event function to send the data to the java backend.
WeChat applet
demo6.wxml

<button bindtap="postdata" type="primary">向java后台发送数据</button>

demo6.js

postdata(){
    
    
    var that = this;
    wx.request({
    
    
      url: 'http://localhost:8080/LocationProject/save_data',
      method: 'GET',
      data: {
    
    username: "tiger", userpass: "123456"},
      header:{
    
    
        'content-type': 'application/json'
      },
      success: function(res){
    
    
        console.log("success");
      },
      fail:function(err){
    
    
        console.log('fail reason:'+err.data);
      }
    })

  },
Attributes Description
url Developer server interface address
data Request parameters (data to be passed)
method HTTP request method (GET/POST)
header Response data type

Note: The json above the POST submission method needs to be changed to this x-www-form-urlencoded, otherwise the data will not be received!

java background code

@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
    
		// TODO Auto-generated method stub
		System.out.println("doget");
		System.out.println(req.getParameter("username"));
		System.out.println(req.getParameter("userpass"));
	}

request legal domain name problem

At the beginning, click the submit data prompt,
Insert picture description here
but the local domain name localhost is not enough when the request legal domain name is added to the backend of the WeChat applet. Is it necessary to buy a server? Although after consulting with the teacher, there is a policy of buying his reimbursement by the server, but after consulting the document, I found that the following method can be used!
Insert picture description here
In the project, you can solve this problem by selecting Details -> Local Settings -> Do not verify legal domain names, but after the project goes online, legal domain names and servers must be used, and then the boss will be reimbursed~

ERR_CONNECTION_REFUSED problem

In the case of ensuring that the url is not wrong, the following error occurs.
Insert picture description here
Reason: The java background server does not run. The
solution is to run the server!
Insert picture description here

running result

Click to send data to the java backend to
Insert picture description here
get the data, success! !
Insert picture description here

Guess you like

Origin blog.csdn.net/zjlwdqca/article/details/112476098