对doget和dopost区别的理解
doget与dopost的区别
GET方法用于获取固定资源,一般并不用于传参数,但是实际开发过程中很多都是在用GET方法来传递参数。
get直接访问:http://write.blog.csdn.net/postedit
web->a标签href->XMLHttprequest->servlet->doget访问固定资源返回固定数据
POST方法用于保存与更新资源,传递参数应用post方法。
post传递参数
web->from action method->post->XMLHttprequest->servlet->dopost->用于保存和更新数据
Filter过滤器举例:
doget在配置过滤器后无法修改编码格式
进入doget
中文测试:??????
dopost在配置过滤器后便可以正常执行
进入dopost
中文测试:艾索德
测试代码:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("进入doget");
String ut=request.getParameter("name");
System.out.println("中文测试:"+ut);
PrintWriter out = response.getWriter();
out.print("成功吧!");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("进入dopost");
String ut=request.getParameter("name");
System.out.println("中文测试:"+ut);
PrintWriter out = response.getWriter();
out.print("成功吧!");
}
过滤器
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-name>filterCharset</filter-name>
<filter-class>filter.filterCharset</filter-class>
</filter>
<filter-mapping>
<filter-name>filterCharset</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
文章来源: laoshifu.blog.csdn.net,作者:红目香薰,版权归原作者所有,如需转载,请联系作者。
原文链接:laoshifu.blog.csdn.net/article/details/78283435
- 点赞
- 收藏
- 关注作者
评论(0)