Implementation of the web page to submit data to the background there are many, what do the following summary
1. Submit the form by form
Form submission form is a very common way to pass the background value by the action attribute of the form can pass values to the background servlet
<form action="UpdateServlet" method="post" >
编号:<input type="text" name="id" value="${user.id}" readonly=" readonly" /><br/>
姓名:<input type="text" name="name" value="${user.name }" /> <br/>
性别:<input type="text" name="sex" value="${user.sex }" /> <br/>
年龄:<input type="text" name="age" value="${user.age }" /> <br/>
<input type="submit" value="更新" />
</form>
2. traditional values ajax
Ajax in the data set may be a value, then the reception in the background example:
$.ajax({
type: 'POST',
url: 'TestJsonServlet',
data: {"id":id,"name":name,"password":password}, //这个data是要往后台传递的data
dataType:"json",
success: function(data,msg){ //这个data 是服务器返回的数据
show(data.data); //第一个data是参数data ,第二个data是返回的 json 数据的名字 data
},
error:function(xhr,errorMsg,error){
alert(xhr.status);
console.log(xhr.status);
alert(errorMsg);
}
});
3. Crossing value href: href attribute set by <a> js tag or pass the link address set to a value in the following format:
<td>
<a href="UpdateServlet?id=${user.id }">更新</a>
<a href="DeleteServlet?id=${user.id }">删除</a>
</td>
4. By jumping servlet to servlet achieve transmission values:
First of all incoming values to UpdateServlet id, the id is updated based on the value of
UpdateServlet?id=${user.id }
Then at UpdateServlet operation based on the value of the id, the last hop in the ShowServlet UpdateServlet, the value of the updated display
request.getRequestDispatcher("ShowServlet").forward(request, response);
5. directly in the address bar of your browser?-After-write value to achieve their goals to pass the background values
http://localhost:8080/servlet/TestServlet?id=1&name=wang