简体   繁体   English

我是jsp和google app引擎的新手,但出现此错误:此URL不支持HTTP方法GET。

[英]I am new to jsp and google app engine getting this error: HTTP method GET is not supported by this URL

This is my JSP File. 这是我的JSP文件。 It has 3 text fields and a submit button.. 它具有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> 

This is my web.xml 这是我的web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
    <servlet-name>ButtontoServ</servlet-name>
    <servlet-class>pack.exp.ButtontoServServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ButtontoServ</servlet-name>
    <url-pattern>/buttontoserv</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

This is the servlet under pack.exp package with file name ButtontoServServlet.java 这是pack.exp包下的servlet,文件名为ButtontoServServlet.java

package pack.exp;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class ButtontoServServlet extends HttpServlet 
{
    protected void doPost(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);
    }
}

When I am deploying it to the google app engineit is throwing this error "Error: HTTP method GET is not supported by this URL" 当我将其部署到Google App Engine时,它会引发此错误“错误:此URL不支持HTTP方法GET”

I also tried on tomcat and the error says "HTTPO 405 Method not allowed. The website cannot display the page HTTP 405 Most likely cause: •The website has a programming error." 我也尝试了tomcat,错误消息为“不允许使用HTTPO 405方法。该网站无法显示页面HTTP 405最有可能的原因:•该网站存在编程错误。”

As your servlet has only doPost method. 由于您的servlet只有doPost方法。 So, you can't get access the servlet with URL. 因此,您无法使用URL访问servlet。 Your URL should be for JSP page where action="buttontoserv" is assigned. 您的URL应该用于分配了action="buttontoserv" JSP页面。 When you click the submit button of JSP page than it will forwarded to /buttontoserv servlet. 当您单击JSP页面的/buttontoserv按钮时,它将被转发到/buttontoserv servlet。

To solve your problem, you should include a doGet method on Servlet or forward to Servlet with form submit from JSP page. 为了解决您的问题,您应该在Servlet上包含一个doGet方法,或者使用从JSP页面提交的表单将其转发到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);
    }
}

Make sure you type the url to the jsp file instead of the servlet. 确保您将URL键入到jsp文件而不是servlet。 Also try overriding the doGet method too like: 也可以尝试覆盖doGet方法,例如:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我收到“此 URL 不支持 HTTP 方法 GET”错误? - Why I am getting 'HTTP method GET is not supported by this URL' error? Java:Google App Engine“此URL不支持HTTP方法POST”错误 - Java: Google App Engine “HTTP method POST is not supported by this URL” error 此网址不支持在Google App Engine 405 HTTP方法GET中获取此错误 - Getiing this error in google app engine 405 HTTP method GET is not supported by this URL 为什么我在此代码中的任何地方都没有使用此URL不支持的错误HTTP GET方法 - Why I am getting error HTTP GET method not supported by this URL, while I am not using it anywhere in my code 从JSP调用servlet时出现“ HTTP状态405 –此URL不支持HTTP方法GET”错误 - “HTTP Status 405 – HTTP method GET is not supported by this URL” error when calling servlet from JSP 不支持请求方法“GET”。 为什么我会收到此错误? - Request method 'GET' not supported. Why am I getting this error? 部署到Google App Engine时出现错误 - While Deploying to Google app engine I am getting error Spring JSP到控制器的重定向错误:此URL不支持HTTP方法POST - Spring jsp to controller redirect error :HTTP method POST is not supported by this URL 获取错误HTTP状态405 - 此方法不支持HTTP方法GET但不使用`get`? - getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever? HTTP状态405-此URL不支持HTTP方法GET-RequestDispatcher出现错误 - HTTP Status 405 - HTTP method GET is not supported by this URL - getting error with RequestDispatcher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM