add.jsp
<%
...
@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" />
< title > 无标题文档 </ title >
</ head >
< body >
< form action ="../addDo" method ="post" >
姓名 < input type ="text" name ="name" />< br />
密码 < input type ="text" name ="password" />
< input type ="submit" value ="确定" />
</ form >
</ body >
</ html >
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" />
< title > 无标题文档 </ title >
</ head >
< body >
< form action ="../addDo" method ="post" >
姓名 < input type ="text" name ="name" />< br />
密码 < input type ="text" name ="password" />
< input type ="submit" value ="确定" />
</ form >
</ body >
</ html >
addDo.java
//
Java Document
import java.io. * ;
import javax.servlet. * ;
import javax.servlet.http. * ;
public class addDo extends HttpServlet
... {
public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
...{
PrintWriter out = response.getWriter();
out.println("name is:"+request.getParameter("name"));
out.println("password is:"+request.getParameter("password"));
}
}
import java.io. * ;
import javax.servlet. * ;
import javax.servlet.http. * ;
public class addDo extends HttpServlet
... {
public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
...{
PrintWriter out = response.getWriter();
out.println("name is:"+request.getParameter("name"));
out.println("password is:"+request.getParameter("password"));
}
}
web.xml
<?
xml version="1.0" encoding="GB2312"
?>
< web-app >
< servlet >
< servlet-name > addDo </ servlet-name >
< servlet-class > addDo </ servlet-class >
</ servlet >
< servlet-mapping >
< servlet-name > addDo </ servlet-name >
< url-pattern > /addDo </ url-pattern >
</ servlet-mapping >
</ web-app >
< web-app >
< servlet >
< servlet-name > addDo </ servlet-name >
< servlet-class > addDo </ servlet-class >
</ servlet >
< servlet-mapping >
< servlet-name > addDo </ servlet-name >
< url-pattern > /addDo </ url-pattern >
</ servlet-mapping >
</ web-app >