对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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

红目香薰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值