Java 我是jsp和google应用程序引擎的新手,遇到了这个错误:这个URL不支持HTTP方法GET

Java 我是jsp和google应用程序引擎的新手,遇到了这个错误:这个URL不支持HTTP方法GET,java,google-app-engine,jsp,servlets,Java,Google App Engine,Jsp,Servlets,这是我的JSP文件。它有3个文本字段和一个提交按钮 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>

这是我的JSP文件。它有3个文本字段和一个提交按钮

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
  </head>
<body>
   <form action="buttontoserv" method="post">
    <input type="text" name="name"/><br>        
    <input type="text" name="group"/>
    <input type="text" name="pass"/>
    <input type="submit" value="submit">            
  </form>
</body>
</html> 
当我将它部署到google应用程序引擎时,它抛出了这个错误 “错误:此URL不支持HTTP方法GET”

我也试过tomcat,错误是 “不允许使用HTTPO 405方法。网站无法显示HTTP 405页面
最可能的原因是:•网站出现编程错误。”

请确保键入jsp文件的url,而不是servlet。也可以尝试覆盖doGet方法,如:

protected void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException 
    {
         doPost(request, response);
    }

因为servlet只有
doPost
方法。因此,您无法使用URL访问servlet。您的URL应该是分配了
action=“buttonoserv”
的JSP页面的URL。当您单击JSP页面的提交按钮时,它将转发到
/buttonoserv
servlet

为了解决您的问题,您应该在Servlet上包含一个
doGet
方法,或者使用表单submitfromjsp页面转发到Servlet

public class ButtontoServServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request,
        HttpServletResponse response)
            throws ServletException, IOException {
    String name = request.getParameter("name");
    String group = request.getParameter("group");
    String pass = request.getParameter("pass");
    System.out.println("Name :"+ name);
    System.out.println("group :"+ group);
    System.out.println("pass :"+ pass);

    }    
    @Override
    protected void doGet(HttpServletRequest request,
             HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, 
            HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }
}

在@jsjunkie中添加一个正斜杠,得到相同的错误。这在我的Tomcat服务器上没有问题。这可能是谷歌应用程序引擎的问题。@Masud它在我的tomcat中给出了错误。我的tomcat与其他程序配合良好。单击“提交”按钮后,请发布您在浏览器中看到的url。您可以屏蔽i.p.“我想从上下文路径开始查看URL”。@Asim在哪里键入jsp文件的URL?我还添加了doGet函数。但还是一样problm@Shanx,最好的方法是保持doGet和doPost,并在这里调用common
processRequest(请求,响应)方法。我用Servlet代码更新了答案。@Shanx,它显示空白页,因为Servlet上没有写任何东西。@Masud但是先生,为什么它没有显示包含3个文本字段和jsp按钮的jsp页面,您应该使用另一个链接,比如,这里MyJSP.jsp是web文件夹的jsp页面。
protected void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException 
    {
         doPost(request, response);
    }
public class ButtontoServServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request,
        HttpServletResponse response)
            throws ServletException, IOException {
    String name = request.getParameter("name");
    String group = request.getParameter("group");
    String pass = request.getParameter("pass");
    System.out.println("Name :"+ name);
    System.out.println("group :"+ group);
    System.out.println("pass :"+ pass);

    }    
    @Override
    protected void doGet(HttpServletRequest request,
             HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, 
            HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }
}