[英]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.