The difference between doget and dopost
The GET method is used to obtain fixed resources and is generally not used to pass parameters, but in the actual development process, many of them use the GET method to pass parameters.
Get direct access: http://write.blog.csdn.net/postedit
web->a tag href->XMLHttprequest->servlet->doget accesses fixed resources and returns fixed data
The POST method is used to save and update resources, pass parameters and apply the post method.
post parameters
web->from action method->post->XMLHttprequest->servlet->dopost->used to save and update data
Filter example:
Doget cannot modify the encoding format after configuring the filter
Enter doget
Chinese test:??????
dopost can be executed normally after configuring the filter
Enter the dopost
Chinese test: Isood
Test code:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("进入doget");
String ut=request.getParameter("name");
System.out.println("Chinese test:"+ut);
PrintWriter out = response.getWriter();
out.print("Success!");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Enter dopost");
String ut=request.getParameter("name");
System.out.println("Chinese test:"+ut);
PrintWriter out = response.getWriter();
out.print("Success!");
}
filter
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf8");
response.setCharacterEncoding("utf8");
response.setContentType("text/html;charser=utf8");
chain.doFilter(request, response);
}
filter
<filter>
<filter-name>filterCharset</filter-name>
<filter-class>filter.filterCharset</filter-class>
</filter>
<filter-mapping>
<filter-name>filterCharset</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>