servlet中doget和dopost的区别

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:09:21
我想问问servlet中doget和dopost的区别是什么 我知道doget是传输比较小一点的数据而dopost是传输比较大一点的数据, 我在myeclipse里面新建servlet的时候会自动生成一个servlet 然后里面自动有doget和dopost的方法 可是我把doget方法删了后 运行servlet时 在网页中没有显示,然后我把dopost方法删了后 没有什么影响 张扬能运行成功 真是为什么呀

form中可以写是用method="get"还是method="post"
get的话调用doGet()
url显示:
http://xx.xx.xx/xxxServlet?username=abc+password=abc
post的话调用doPost()
url显示:http://xx.xx.xx/xxxServlet

一般来说我们是用不到doGet方法的,doGet方法是servlet提交报头数据之类的用的,doGet方法提交表单的时候会在url后边显示提交的内容,所以不安全。而且doGet方法只能提交256个字符。doPost则没有这个限制。通常我们使用的都是doPost方法,你只要在servlet中让这两个方法互相调用就行了,例如在 doGet方法中这样写
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request,response);
}

再把业务逻辑直接写在doPost方法中。servlet碰到doGet方法调用直接就会去调用doPost因为他们的参数都一样。而且doGet方法处理中文问题很困难,要写过滤器之类的。

不要自己对servlet进行修改阿,那是系统自己生成的