只截取doget和dopost方法,其中doget方法如果为空的话程序就不能执行成功,但是如果反过来,dopost为空 把程序写在doget里,这时程序可以正常运行,这是为什么?
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  // TODO Auto-generated method stub } /**  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)  */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  // TODO Auto-generated method stub  response.setContentType("text/html;charset=UTF-8");  PrintWriter out = response.getWriter();  out.print("<html>");  out.print("<body>");  out.print("<h1>登陆界面</h1>");  out.print("<form action=yanzheng method=post>");  out.print("用户名:<input type=text name=username><br>");  out.print("密码:<input type=password name=password><br>");  out.print("<input type=submit name=login><br>");  out.print("</form>");  out.print("</body>");  out.print("</html>"); }

解决方案 »

  1.   

    <form action="" method="get">
    </form>
    你页面里面应该规定的是get吧?所以调用servlet中的doGet方法
      

  2.   

    调用什么方法是与提交方式有关的,你出现的这种状况应该是因为你用的是get方法提交
      

  3.   

    doGet和doPost方法,分别是用来处理来自于请求中GET和POST方式提交的请求,请求方式对应form中的method属性。
      

  4.   

    form表单默认提交是GET方式。指定action="POST",那么会以POST方式提交.
    相应的,servlet中对应doGet、doPost方法处理。
      

  5.   

    你的程序用到doGet方法了
    可以在doGet方法里写上this.doPost();
      

  6.   

    如果你不指定表单的提交方式,servlet默认走doget().
      

  7.   

    这个程序直接运行就画出一个html,不存在另外一个html设置get还是post
      

  8.   

    如果你的方法写在doGet里面,那你就在doPost里面写上this.doGet(request, response);
    如果你的方法写在doPost里面,那你在doGet里面写上this.doPost(request, response);
    试试
      

  9.   

    根据你FROM表单里的。method决定的
      

  10.   

    一个简单的办法就是在doGet()方法里面调用doPost()方法