在一开始,只要用微信提供的接口就好,即we.request,然后设置相应的参数就好,可是在设置参数的时候我遇到了问题,即不太明白如何动态设置要传递的参数,会获取输入框的值但并不能设置到we,rewuest中
看代码
wxml

 <input bindinput="inputdd" placeholder="输入要删除的学号"></input>
        <view>
    <button bindtap='bindtest'>test</button>
</view>
data: {
    no : '',
    abc:'',
    inputDate :'',
    iconSize: [20, 30, 40, 50, 60, 70],
    iconColor: [
      'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
    ],
    iconType: [
      'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
    ]
  },
  inputdd: function(e){
    this.setData({
      inputDate : e.detail.value
    })
    },
  bindtest: function () {
    wx.request({
      url: 'http://localhost:8888/StudentMannger/delteservlet',  //本地服务器地址
      data: {
        sno: this.data.inputDate,
        // 对于我来说上面这句话就是困扰我很久的东西
      },
      method: 'GET',
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        console.log(res.data);
       
      },
      fail: function (res) {
        console.log("失败");
      }
    })
  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     this.setData({
      no: inputDate,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

 

```java
package ding.stu.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ding.stu.service.deleteservice;

@WebServlet("/delteservlet")
public class delteservlet extends HttpServlet {
	public delteservlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 1设置编码
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		/* 设置响应头允许ajax跨域访问 */
		response.setHeader("Access-Control-Allow-Origin", "*");
		/* 星号表示所有的异域请求都可以接受, */
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		// 获取微信小程序get的参数值并打印
		// String no = request.getParameter("sno");
		// 2获取值
		String no = request.getParameter("sno");
		deleteservice del = new deleteservice();
		boolean b = del.delete(no);
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		if (b == true) {
			out.print("删除成功");
		} else {
			out.print("不存在此人");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐