【发布时间】:2010-09-02 02:42:18
【问题描述】:
根据here 给出的示例,我编写了一个 servlet 来处理 POST 和 GET 请求。我有以下内容:
具有以下格式的 html:
form method="POST" action="servlet/RequestType"
然后输入:
input type="submit" value="POST"
以下doGet 和doPost 方法:
public void doGet(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
rsp.setContentType("text/html");
PrintWriter out = rsp.getWriter();
String requestType = req.getMethod();
out.println("<html>");
out.println("<head><title> Request Type: " + requestType
+ " </title></head>");
out.println("<body>");
out.println("<p>This page is the result of a " + requestType
+ " request.</p>");
out.println("</body></html>");
}
public void doPost(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
doGet(req, rsp);
}
输出应该是:
此页面是 POST 请求的结果。
但我得到了:
此页面是 GET 请求的结果。
有人知道为什么会这样吗?
【问题讨论】:
-
我看不到你的 HTML。您确定在 HTML
-
是的,我刚刚编辑了我的帖子以显示我的表单,它以前没有显示,因为 html 标签,我想。无论如何,这是我的表单:
-
我遇到了类似的问题..检查这个解决方案:stackoverflow.com/questions/8695795/…