java - GAE servlet 的 doPost() 不起作用

标签 java google-app-engine jsp servlets

我是 JSP 初学者,我有以下 servlet:

@SuppressWarnings("serial")
public class HelloAppIgorServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        RequestDispatcher disp = req.getRequestDispatcher("/mainpage.jsp");
        disp.forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter pw = resp.getWriter();
        pw.print("Test");
        pw.close();
    }
}

和一个名为 mainpage.jsp 的 JSP 文件:

<%@ 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>
    <p>Hello there!<p>
    <form action="." method="post">
        <input type="text" name="name1" />
        <input type="submit" value="name2" />
    </form>
</body>
</html>

问题是 doPost() 方法不起作用。当我单击按钮时,它会将我重定向到 index.html 页面。我确定问题不在 servlet 中,那么它会在哪里呢?

最佳答案

您需要在 <form action="." method="post"> 中设置适当的操作.该操作是您通过 <servlet-mapping> 定义的 servlet 的(相对)URL在web.xml .

关于java - GAE servlet 的 doPost() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17516948/

相关文章:

java - 更好的算法?更好的阵列?

java - 如何为 wsdl 生成 JSP 文件

java - if else 语句不工作 jsp

java - Google App Engine 的 .net 包装器?

python - 如何在谷歌应用引擎(python)中创建一个excel文件?

java - WAR 安装错误的编码解决方案(Websphere Portal 6.0)?

java - 服务器重启或崩溃后的计划任务

java - Play Framework - 为 Assets 定义 404 页面

java - 有没有一种方法可以将对象设置为重叠并符合网格系统?

java - Google App Engine Warfile 目录结构