我尝试将数据从 jsp 表单发送到 servlet,但我无法读取通过 servlet 中的 POST 方法发送的数据。这是小服务程序代码
public class TUhServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String s= req.getParameter("post_text");
System.out.println(s);
resp.sendRedirect("/tuh.jsp");
}
}
这是 tuh.jsp 中的形式
<form class="post_form" action="./"
method="post" enctype="multipart/form-data">
0"/><br/>
Message : <input name="post_text" type="text" size="30" maxlength="30"/>
<p><input type="submit" value="Post!"/></p>
<input type="hidden" name="type" value="post"/>
</form>
web.xml
<servlet>
<servlet-name>TUh</servlet-name>
<servlet-class>tuh.TUhServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TUh</servlet-name>
<url-pattern>/tuh</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>tuh.jsp</welcome-file>
</welcome-file-list>
</web-app>