package com.chen.model;
import java.sql.Date;
public class User {
private String id;
private String userName;
private Date birthDate;
private String sex;
private String hobby;
private String education;
private String resume;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getResume() {
return resume;
}
public void setResume(String resume) {
this.resume = resume;
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<h1>请填写注册信息</h1>
<form method="get" action="/javaweb0530/LoginServlet">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="userName"></td>
</tr>
<tr>
<td> 密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td> 密码验证:</td>
<td><input type="password" name="rpassword"></td>
</tr>
<tr>
<td> 姓名:</td>
<td><input type="text" name="userName"></td>
</tr>
<tr>
<td> 出生日期:</td>
<td><input type="text" name="birthDate"></td>
</tr>
<tr>
<td> 性别:</td>
<td>
<intput type="radio" name="sex" value="男" checked/>男
<intput type="radio" name="sex" value="女"/>女
</td>
</tr>
<tr>
<td> 爱好:</td>
<td>
<input type="checkbox" name="sport" value="lvyou">旅游<br>
<input type="checkbox" name="sport" value="dengshan">登山<br>
<input type="checkbox" name="sport" value="jianshen">健身<br>
<input type="checkbox" name="sport" value="shangwang">上网<br>
<input type="checkbox" name="sport" value="youyong">游泳<br>
</td>
</tr>
<tr>
<td> 学历:</td>
<td>
<select name="eduction">
<option value="benke">本科生</option>
<option value="shuoshi">硕士生</option>
<option value="boshi">博士生</option>
</td>
</tr>
<tr>
<td> 简历:</td>
<td><input type="textarea" name="resume"></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="提交"/>
<input type="reset" name="重置"/>
</td>
</tr>
</table>
</form>
</body>
</html>
package com.ttc.login;
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 LoginServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public LoginServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* 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();
//从request对象里获取用户名,密码
String userName = request.getParameter("userName");
String password = request.getParameter("password");
System.out.println(userName + password);
//验证用户名和密码是否正确
//在db中验证
if("java".equals(userName)&&"java".equals(password)){
out.println("welcome " + userName );
}else{
out.println("用户名或者密码出错");
}
//根据验证结果,输出响应信息 1用户出错 2 密码出错 3 2者出错
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* 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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form method="get" action="/javaweb0530/LoginServlet">
用户名:<input type="text" name="userName"><br>
密码:<input type="password" name="password"><br>
<input type="submit" name="login"><br>
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>hello</servlet-name>
<servlet-class>com.ttc.test.HelloServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.ttc.login.LoginServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ReadRequestInfo</servlet-name>
<servlet-class>com.ttc.test.ReadRequestInfo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/helloservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ReadRequestInfo</servlet-name>
<url-pattern>/ReadRequestInfo</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>01/hello.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
jdbcDriver = oracle.jdbc.driver.OracleDriver
jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl
jdbcUser = SCOTT
jdbcPassword = TIGER
package demo1;
/**
* JDBC示例1
*/
import java.sql.*;
/**
* @author Administrator
* �