首页 新闻 会员 周边 捐助

如何用java servlet 写一个添加id的功能 我是初学者

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-08-30 20:15

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);
}


}

kme笑笑的主页 kme笑笑 | 初学一级 | 园豆:154
提问于:2015-08-23 23:09
< >
分享
所有回答(1)
0

不明白你的意思,添加到数据库?

稳稳的河 | 园豆:4216 (老鸟四级) | 2015-08-24 20:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册