问个傻点的问题,我想知道
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
   ......
}
中request,response参数是如何传入的

解决方案 »

  1.   

    request是服务器接收客户端的请求。。如:
    String name=request.getParamete("name");
    这就表示接收客户端请求name的参数response是服务器响应客户端请求,返回信息给客户端。。如:
    response.sendRedirect("页面.jsp");
    表示服务器处理了客户端的请求后,响应给客户端,客户端的浏览器就可以看到页面.jsp了。
      

  2.   


    public class CheckYearlyCardId extends HttpServlet { /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { this.doPost(request, response);
    } /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    YearlyCheckServiceDAO yearlyDao=new YearlyCheckServiceDAO();
    String associatorCardId=request.getParameter("associatorCardId");
    System.out.println(associatorCardId);
    if(yearlyDao.findYearlyCheckByassociatorCardId(associatorCardId)==true){
    out.print("会员卡ID已存在!");
    }else{
    out.print("会员卡ID不存在!");
    }
    }}给楼主一个例子 结合1楼理论 看看
      

  3.   

    呵呵,我就是想知道tomcat服务器是如何执行doGet()这个方法,又如何将参数传进去的
      

  4.   


    自己去找servlet的源代码看看
      

  5.   

    3楼的兄弟专业点好不好,呵呵,不光是拿分的吧!
    我的意思是谁调用了这个doGet(request,response)方法
      

  6.   

    是用web服务器调用的,如tomcat,它来调用的
      

  7.   

    先是服务器,拦截了请求,转发给 servlet 中的 service() 方法分发请求protected   void   service(HttpServletRequest   req,   HttpServletResponse   resp)   
                      throws   ServletException,   IOException   
              {   
                      String   method   =   req.getMethod();   
                      if(method.equals("GET"))   
                      {   
                              long   lastModified   =   getLastModified(req);   
                              if(lastModified   ==   -1L)   
                              {   
                                      doGet(req,   resp);   
                              }   else   
                              {   
                                      long   ifModifiedSince   =   req.getDateHeader("If-Modified-Since");   
                                      if(ifModifiedSince   <   (lastModified   /   1000L)   *   1000L)   
                                      {   
                                              maybeSetLastModified(resp,   lastModified);   
                                              doGet(req,   resp);   
                                      }   else   
                                      {   
                                              resp.setStatus(304);   
                                      }   
                              }   
                      }   else   
                      if(method.equals("HEAD"))   
                      {   
                              long   lastModified   =   getLastModified(req);   
                              maybeSetLastModified(resp,   lastModified);   
                              doHead(req,   resp);   
                      }   else   
                      if(method.equals("POST"))   
                              doPost(req,   resp);   
                      else   
                      if(method.equals("PUT"))   
                              doPut(req,   resp);   
                      else   
                      if(method.equals("DELETE"))   
                              doDelete(req,   resp);   
                      else   
                      if(method.equals("OPTIONS"))   
                              doOptions(req,   resp);   
                      else   
                      if(method.equals("TRACE"))   
                      {   
                              doTrace(req,   resp);   
                      }   else   
                      {   
                              String   errMsg   =   lStrings.getString("http.method_not_implemented");   
                              Object   errArgs[]   =   new   Object[1];   
                              errArgs[0]   =   method;   
                              errMsg   =   MessageFormat.format(errMsg,   errArgs);   
                              resp.sendError(501,   errMsg);   
                      }   
              }