package cn.itcast;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Demo1 extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//设置从页面读取数据的编码格式
request.setCharacterEncoding("UTF-8");
//通过input的名称获取input的value值
String idNum = request.getParameter("idNum");
System.out.println(idNum);
//设置浏览器输出的文本的编码
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
response.getWriter().write("添加成功");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//设置浏览器输出的文本的编码
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String s = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>"+
"<html>"+
" <head>"+
" <title>Demo1.html</title>"+
" <meta http-equiv='content-type' content='text/html; charset=UTF-8'>"+
" </head>"+
" <body>"+
" <form action='http://localhost:8080/ServletDemo/Demo1' method='POST' >"+
" <table border='1'>"+
" <tr>"+
" <td>身份证号码:</td>"+
" <td><input type='text' name='idNum'></td>"+
" </tr>"+
" <tr>"+
" <td colspan='2' align='center'>"+
" <input type='submit' value='提交'>"+
" </td>"+
" </tr>"+
"</table>"+
"</form>"+
" </body>"+
"</html>";
response.getWriter().write(s);
}
}
不明白你的意思,添加到数据库?