直接URL没问题,但是点提交就不行。
package test; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; //@WebServlet("/test/FormDeal") public class FormDeal extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ response.setContentType("text/html; charset=gb2312"); request.setCharacterEncoding("GB2312"); PrintWriter out = response.getWriter(); String name = request.getParameter("Name"); String sex = request.getParameter("Sex"); out.println("<html>"); out.println("<head>"); out.println("<meta http-equiv = "Content-Type" content="text/html; charset=gb2312">"); out.println("<title>Your Information</title>"); out.println("</head>"); out.println("<body>"); out.println("<h3>Data You Posted</h3>"); out.println("<table>"); out.println("<tr>"); out.println("<td>你的姓名:</td>"); out.println("<td>"+name+"</td>"); out.println("</tr>"); out.println("<tr>"); out.println("<td>你的性别:</td>"); out.println("<td>"); /*if(sex.equals("1")) out.println("男</td>"); else out.println("女</td>");*/ out.println("</tr>"); out.println("</table>"); out.println("</body>"); out.println("</html>"); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ doGet(request, response); } }
<servlet>
<servlet-name>FormDeal</servlet-name>
<display-name>FormDeal</display-name>
<description>A test for servlet.</description>
<servlet-class>test.FormDeal</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormDeal</servlet-name>
<url-pattern>/test/FormDeal</url-pattern>
</servlet-mapping>
<html>
<head>
<title>Input Information</title>
</head>
<body>
<h3>请输入信息</h3>
<form action=”test/FormDeal” name=”ourform” method=”get”>
姓名:<input type=text name=”Name”/><br/>
性别:<select name=”Sex”>
<option value=”1″ selected>男</option>
<option value=”2″>女</option>
</select>
<br/>
<input type=”submit” name=”Submit” value=”提交”/>
<input type=”reset” name=”Submit2″ value=”重置”/>
</form>
</body>
</html>
10
5
<form action="${pageContext.request.contextPath}/test/FormDeal" name="ourform" method="get">
表单提交路径改一下
5
form表单的action 写错了
5