我是 servlet 的新手,我开发了一个 html 页面,它有一个触发我的 servlet 的提交按钮。一切正常。但现在我想使用 GET 方法,因为我的 html 页面没有发布任何内容。因此我做了以下更改: 1) 在我的 page.html 文件中,我将 method="POST" 替换为 method="GET"。2)我在我的servlet 中用doGet 改变了doPost。但我收到“此处不允许获取”的错误消息。为什么会这样?以下是正常工作的原始文件(在进行更改之前):
我的 page.html 页面:
<html>
<head>
<title>A simple revision of servlets</title>
</head>
<body>
<form method="POST" action="Idiot">
<input type="SUBMIT">
</form>
</body>
</html>
我的部署描述符:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>TangoCharlie</servlet-name>
<servlet-class>Revise</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TangoCharlie</servlet-name>
<url-pattern>/Idiot</url-pattern>
</servlet-mapping>
</web-app>
最后是我的名为 Revise.java 的 servlet 文件
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Revise extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body><h3>Hello India</h3></body></html>");
out.println("Hello");
}
}