/** * Constructor of the object. */ public Mytest() { super(); }
/** * Destruction of the servlet.
*/ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here }
/** * The doGet method of the servlet.
* * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312"); PrintWriter out = response.getWriter(); String id=(String)request.getParameter("id"); Connection con=null; try{
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response);
}
/** * Initialization of the servlet.
* * @throws ServletException if an error occure */ public void init() throws ServletException { // Put your code here }
import java.io.*; public class ASSICTOGBR2312 { public static String trans(String ass){ String res=null; byte temp[]; try{ temp=ass.getBytes("iso-8859-1"); res=new String(temp); } catch(UnsupportedEncodingException en) { System.out.println(en.toString()); }
return res;
} }
5:web.xml
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> This is the description of my J2EE component This is the display name of my J2EE component Mytest com.test.Mytest
Mytest /servlet/Mytest
6: 其中数据库结构如下: 数据库名:hptest 表:userinf 用下面的命令建一个数据库和表 create database hptest; create table userinf ( userid int(4) not null, name char(10) not null, address varchar(50), year date, constraint fk_userinf primary key(userid)); ) insert into userinf values(19,'hp','cq','1982-10-22');