<form action="servlet_in" method="post">
<div class="hom-add-box">
<label>用户名:</label> <input type="text" id="hom-in-username">
</div>
<div class="hom-add-box">
<label>密码:</label> <input type="password" id="hom-in-password">
</div>
<div class="hom-add-box">
<label>登陆类型:</label>
<select>
<option>用户</option>
<option>管理员</option>
</select>
</div>
<div class="hom-add-box">
<input type="submit" value="登陆" id="submit" />
</div>
</form>
servlet_in中dopost是这样写的:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("GB18030");
String username=request.getParameter("hom-in-username");
String password=request.getParameter("hom-in-password");
request.setAttribute("name", username);
request.setAttribute("password", password);
request.getRequestDispatcher("hom.jsp").forward(request, response);
}
xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>j2ee-demo</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>servlet_in</servlet-name>
<servlet-class>page.servlet_in</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet_in</servlet-name>
<url-pattern>/servlet_in</url-pattern>
</servlet-mapping>
</web-app>
黑女2008
慕粉1555408013