0

我正在尝试使用googleappengine. 我的代码如下。我想做的只是通过 html 给出的任何输入,它应该在 servlet 中接收并再次显示在浏览器上。

public class TestServerServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        try{


        String name= req.getParameter("name");
        String msg = req.getParameter("message");


            resp.setContentType("text/plain");
        resp.getWriter().println("user name is"+name);


        }catch(Exception e)
        {
            System.err.println(e);
        }


    }

}

索引.html:

<html>
<head>
<meta charset="ISO-8859-1">
<title>Submission Form</title>
</head>
<body>
<from method="POST" action ="TestServer">
Mail id: <input type ="text" name ="name"/><br/>
Message: <input type ="text" name ="message"/><br>
<input type="submit" value="Submit" />
</from>
</body>
</html>

网页.xml:

<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>TestServer</servlet-name>
        <servlet-class>com.example.test.TestServerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServer</servlet-name>
        <url-pattern>/testserver</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

所以,当我在浏览器上运行时http://localhost:8088/index.html,会显示 html 表单,但我无法查看输出。有人可以建议我哪里出错了吗?

4

0 回答 0