Java的doGet方法是做什么用的

来源:百度知道 编辑:UC知道 时间:2024/06/03 00:07:22

你想问的是servlet里面的doGet方法吧
doget 是接收网页用get方法时调用的
get方法就象你在网页的地址栏里看到的一堆乱码,也就是url后面有参数
作用主要处理请求和响应信息
其实知不知道都没什么,你可以在servlet里把功能都写到一起
然后在一个方法里调用另一个方法就可以了
比如
public void doPost(HttpServletRequest request,HttpServletResponse)
throws ServletException,IOException
{
doGet(request,response);
}
呵呵,手上没有servlet的书,不知道方法写的对不对,不过大概就是这个意思

它用来处理页面表单提交的get请求,比如:
<form action="myServlet" method="get"> //如果method属性的值是"get",就对应servlet里的doGet方法,如果是method="post",就对应servlet里的doPost方法

一般来说都是在doGet方法里写好相应的处理,然后在doPost方法里调用doGet方法,比如:

public void doGet(HttpRequest request,HttpResponse response)throw ServletException,IOException {
//相应的处理
}

public void doPost(HttpRequest request,HttpResponse response)throw ServletException,IOException {
doGet(request,response);
}