eclipse+Java+Servlet+filter+javascript+html+jsp+EL登入注册更新个人信息
数据库sql用vs2008或者mysql用mysql
代码粗糙,提示信息未处理融洽
软工实践的代码
配置文件两个,一个是连接sql 的,另一个是连接mysql的
http://tieba.baidu.com/p/4132531174
http://tieba.baidu.com/p/4239595151
package jianYan;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
/**
* Servlet Filter implementation class CharacterEncodingFilter
*/
@WebFilter("/CharacterEncodingFilter")
public class CharacterEncodingFilter implements Filter {
/**
* Default constructor.
*/
public CharacterEncodingFilter() {
// TODO Auto-generated constructor stub
}
/**
* @see Filter#destroy()
*/
protected FilterConfig fConfig;
protected String encoding="";
public void destroy() {
// TODO Auto-generated method stub
this.fConfig=null;
this.encoding = null;
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
request.setCharacterEncoding(this.encoding);
response.setCharacterEncoding(this.encoding);
response.setContentType("text/html;charset="+this.encoding);
// pass the request along the filter chain
chain.doFilter(request, response);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
this.fConfig=fConfig;
this.encoding = fConfig.getInitParameter("encoding");
}
}
package jianYan;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet Filter implementation class JiaoYanQi
*/
@WebFilter("/JiaoYanQi")
public class JiaoYanQi implements Filter {
/**
* Default constructor.
*/
public JiaoYanQi() {
// TODO Auto-generated constructor stub
}
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
HttpServletRequest QingQiu=(HttpServletRequest)request;
HttpServletResponse HuiYing=(HttpServletResponse)response;
QingQiu.setCharacterEncoding("utf-8");
HuiYing.setCharacterEncoding("utf-8");
String username=(String)QingQiu.getSession().getAttribute("username");
if(username==null)
{
request.setAttribute("meg", "您还没有登录");
System.out.println("no sign");
//this.getServletContext().setAttribute( "XiaoXi","您还没有登录");
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
else
// pass the request along the filter chain
chain.doFilter(request, response);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}
package jianYan;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
/**
* Servlet Filter implementation class Person
*/
@WebFilter("/Person")
public class Person implements Filter {
/**
* Default constructor.
*/
public Person() {
// TODO Auto-generated constructor stub
}
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
HttpServletRequest QingQiu=(HttpServletRequest)request;
//HttpServletResponse HuiYing=(HttpServletResponse)response;
ZhuCe BeanJ=(ZhuCe)QingQiu.getAttribute("bea");
if(BeanJ==null)
{
request.getRequestDispatcher("/personalsee.jsp").forward(request,response);
}else
// pass the request along the filter chain
chain.doFilter(request, response);
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}
package jianYan;
import java.util.HashMap;
import java.util.Map;
public class ZhuCe
{
private String username;
private String password;
private String p1;
private String sex;
private String year;
private String monthTime;
private String day;
private String phone;
private String postnum;
private String iden;
private String degree;
private Map<String,String>error=new HashMap<String,String>();
public Map<String,String>getErrors(){return error;}
public void setErrors(Map<String,String> err)
{
this.error=err;
}
public void setOnlyerror(String key,String value)
{
error.put(key, value);
}
public boolean validate_ZhuCe()
{
boolean flags=true;
if(this.username==null||
this.username.length()>12||
this.username.trim().equals("")||!this.username.matches("[a-zA-Z]{1,12}"))
{
flags=false;
error.put("u1", "用户名必须是1-12位的字母");
}
if(this.password==null||this.password.trim().equals("")||this.password.length()>8)
{
flags=false;
error.put("p1", "密码长度小于等于8");
}
if(this.p1!=null)
{
if(!this.p1.equals(this.password))
{
flags=false;
error.put("p2", "两次密码不一致");
}
}
this.year+="-"+this.monthTime+"-"+this.day;
return flags;
}
public int size()
{
return 11;
}
public String getValue(String str1)
{
if(str1.equals("username"))
return this.username;
else if(str1.equals("password"))
return this.password;
else if(str1.equals("p1"))
return this.p1;
else if(str1.equals("sex"))
return this.sex;
else if(str1.equals("year"))
return this.year;
else if(str1.equals("monthTime"))
return this.monthTime;
else if(str1.equals("day"))
return this.day;
else if(str1.equals("phone"))
return this.phone;
else if(str1.equals("postnum"))
return this.postnum;
else if(str1.equals("iden"))
return this.iden;
else if(str1.equals("degree"))
return this.degree;
else return "";
}
public boolean setValue(String str1,String str2)
{
if(str1.equals("username"))
this.username=str2;
else if(str1.equals("password"))
this.password=str2;
else if(str1.equals("p1"))
this.p1=str2;
else if(str1.equals("sex"))
this.sex=str2;
else if(str1.equals("year"))
this.year=str2;
else if(str1.equals("monthTime"))
this.monthTime=str2;
else if(str1.equals("day"))
this.day=str2;
else if(str1.equals("phone"))
this.phone=str2;
else if(str1.equals("postnum"))
this.postnum=str2;
else if(str1.equals("iden"))
this.iden=str2;
else if(str1.equals("degree"))
this.degree=str2;
else return false;
return true;
}
public String getUsername()
{
return username;
}
public void setUsername(String user)
{
this.username=user;
}
public String getPassword()
{
return password;
}
public void setPassword(String user)
{
this.password=user;
}
public String getP1()
{
return p1;
}
public void setP1(String user)
{
this.p1=user;
}
public String getsex()
{
return sex;
}
public void setsex(String user)
{
this.sex=user;
}
public String getyear()
{
return year;
}
public void setyear(String user)
{
this.year=user;
}
public String getmonth()
{
return monthTime;
}
public void setmonth(String user)
{
this.monthTime=user;
}
public String getday()
{
return day;
}
public void setday(String user)
{
this.day=user;
}
public String getphone()
{
return phone;
}
public void setphone(String user)
{
this.phone=user;
}
public String getpostnum()
{
return postnum;
}
public void setpostnum(String user)
{
this.postnum=user;
}
public String getiden()
{
return iden;
}
public void setiden(String user)
{
this.iden=user;
}
public String getdegree()
{
return degree;
}
public void setdegree(String user)
{
this.degree=user;
}
}
package login;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class GoOut
*/
@WebServlet("/GoOut")
public class GoOut extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public GoOut() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
request.getSession().removeAttribute("username");
response.sendRedirect("index.jsp");
}
}
package login;
import java.sql.* ;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Login1
*/
@WebServlet("/Login1")
public class Login1 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Login1() {
super();//这个是模版里面的,不知道这个是干甚么用的
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
//搜到的,把这句注释掉解决了乱码问题
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String result = "" ;
//获取用户名
String username = request.getParameter("username") ;
String password= request.getParameter("password") ;
if ((username == "") || (username==null) || (username.length() > 12 ))
{
try{
result = "用户名不能超过12个字符!" ;
this.getServletContext().setAttribute( "XiaoXi",result);
//result=(String)this.getServletContext().getAttribute("XiaoXi");
response.sendRedirect("index.jsp") ;
}catch(Exception e){
System.out.println("yhm");
e.printStackTrace() ;
System.exit(0);
}
return;
}
if ((password== "") || (password==null) || (password.length() > 8 )){
try{
result = "密码不能超过8个字符!" ;
this.getServletContext().setAttribute( "XiaoXi",result);
response.sendRedirect("index.jsp") ;
// request.getRequestDispatcher("/index.jsp").forward(request,response);;
}catch(Exception e)
{
System.out.println("mima");
e.printStackTrace();
System.exit(0);
}
return;
}
String QuDong_JDriver=this.getServletContext().getInitParameter("QuDong_JDriver");
try
{
Class.forName(QuDong_JDriver);
}catch(ClassNotFoundException e)
{
System.out.println("数据库驱动引擎/发动机启动-失败");
e.printStackTrace();
System.exit(0);
}
System.out.println("数据库驱动引擎/发动机启动-成功");
try
{
String YongHu_user=this.getServletContext().getInitParameter("YongHu_user");
String MiMa_password=this.getServletContext().getInitParameter("MiMa_password");
String SJKDiZhi_url=this.getServletContext().getInitParameter("SJKDiZhi_url");
//这里三句也可以直接复制字符串,在这里是去读取配置文件里的对应的值
System.out.println(SJKDiZhi_url+YongHu_user+MiMa_password);
Connection LianJie_con=DriverManager.getConnection(SJKDiZhi_url,YongHu_user,MiMa_password);
System.out.println("数据库连接成功");
Statement MingLing_stmt=LianJie_con.createStatement();
System.out.println("查询");
System.out.println("开始读取数据");
ResultSet JieGuoJi_rs=MingLing_stmt.executeQuery("select *from 用户表 where 用户名='"+username+"' and 密码='"+password+"'");
if(JieGuoJi_rs.next())
{
HttpSession session = request.getSession();
session.setAttribute("username", JieGuoJi_rs.getString("用户编号"));
session.setAttribute("password",password);
System.out.println(JieGuoJi_rs.getString("用户编号")+"\t");
}else
{
MingLing_stmt.close();
LianJie_con.close();
this.getServletContext().setAttribute( "XiaoXi","用户名或密码不匹配。");
response.sendRedirect("index.jsp") ;
return;
}
MingLing_stmt.close();
LianJie_con.close();
System.out.println("读取完毕");
response.sendRedirect("XueHome.jsp") ;
}catch(SQLException e)
{
System.out.println("数据库连接失败");
e.printStackTrace();
System.exit(0);
}
}
}
package login;
import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jianYan.ZhuCe;
import sqlXueChe.MingLing_CMD;
/**
* Servlet implementation class Personload
*/
@WebServlet("/Personload")
public class Personload extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Personload() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
try
{
HttpSession session = request.getSession();
String numberName=(String)session.getAttribute("username");
String sqlYuJu="select * from 用户表 where 用户编号=?";
String QuDong_JDriver=this.getServletContext().getInitParameter("QuDong_JDriver");
String YongHu_user=this.getServletContext().getInitParameter("YongHu_user");
String MiMa_password=this.getServletContext().getInitParameter("MiMa_password");
String SJKDiZhi_url=this.getServletContext().getInitParameter("SJKDiZhi_url");
MingLing_CMD sql_Datrilla=new MingLing_CMD(QuDong_JDriver,SJKDiZhi_url,YongHu_user,MiMa_password);
ResultSet JieGuoJi_rs=sql_Datrilla.ChaKan_select(sqlYuJu,numberName);
JieGuoJi_rs.next();//丢 这一句,报错!!
System.out.println("信息提取"+JieGuoJi_rs.getString("用户名"));
ZhuCe BeanJ=new ZhuCe();
BeanJ.setUsername(JieGuoJi_rs.getString("用户名"));
BeanJ.setsex(JieGuoJi_rs.getString("电子邮箱"));
BeanJ.setyear(JieGuoJi_rs.getString("出生日期"));
BeanJ.setphone(JieGuoJi_rs.getString("联系电话"));
BeanJ.setpostnum(JieGuoJi_rs.getString("备注"));
BeanJ.setdegree(JieGuoJi_rs.getString("专业"));
sql_Datrilla.GuanBi_closecon();
request.setAttribute("bea",BeanJ);
System.out.println("成功提取个人信息");
request.getRequestDispatcher("/personalsee.jsp").forward(request, response);
}catch(Exception err)
{
System.out.println("提取个人信息异常");
err.printStackTrace();
System.exit(0);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// doGet(request, response);
}
}
package login;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.sql.ResultSet;
import jianYan.ZhuCe; //@Datrilla
import sqlXueChe.MingLing_CMD;//@Datrilla
/**
* Servlet implementation class Register
*/
@WebServlet("/Register")
public class Register extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Register() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
//request.setCharacterEncoding("UTF-8");
// response.setCharacterEncoding("UTF-8");
ZhuCe BeanJ=new ZhuCe();
try
{
Enumeration<String> me = request.getParameterNames();
while(me.hasMoreElements())
{
String name = (String) me.nextElement();
String value = request.getParameter(name);
BeanJ.setValue(name, value);
}/*
BeanJ.setUsername(request.getParameter("username"));
BeanJ.setPassword(request.getParameter("password"));
BeanJ.setP1(request.getParameter("p1"));
BeanJ.setsex(request.getParameter("sex"));
BeanJ.setyear(request.getParameter("year"));
BeanJ.setmonth(request.getParameter("monthTime"));
BeanJ.setday(request.getParameter("day"));
BeanJ.setphone(request.getParameter("phone"));
BeanJ.setpostnum(request.getParameter("postnum"));
BeanJ.setiden(request.getParameter("iden"));
BeanJ.setdegree(request.getParameter("degree"));*/
}catch(Exception err)
{
System.out.println("wrong_index2");
err.printStackTrace();
System.exit(0);
//throw new RuntimeException(err);
}
if(BeanJ.validate_ZhuCe()==false)
{
System.out.println("input_error");
Map<String,String> error=BeanJ.getErrors();
request.setAttribute("tips", error);
request.getRequestDispatcher("/index2.jsp").forward(request, response);
return;
}
String sqlpro="{ call 注册用户名验证(?) } ";/*存储过程select查询*/
String sqlYuJu="insert into 用户表(用户名,密码,联系电话,电子邮箱 ,备注,专业,出生日期) "+" values('"
+BeanJ.getUsername()+"','"+BeanJ.getPassword()+"','"+BeanJ.getphone()+"','"+
BeanJ.getsex()+"','"+BeanJ.getpostnum()+"','"+BeanJ.getdegree()+"','"+BeanJ.getyear()+"')";
try
{
String QuDong_JDriver=this.getServletContext().getInitParameter("QuDong_JDriver");
String YongHu_user=this.getServletContext().getInitParameter("YongHu_user");
String MiMa_password=this.getServletContext().getInitParameter("MiMa_password");
String SJKDiZhi_url=this.getServletContext().getInitParameter("SJKDiZhi_url");
MingLing_CMD sql_Datrilla=new MingLing_CMD(QuDong_JDriver,SJKDiZhi_url,YongHu_user,MiMa_password);
ResultSet rs = sql_Datrilla.ChunChu_produce(sqlpro,BeanJ.getUsername());
rs.next();
if(rs.getLong(1)>=1)
{
BeanJ.setOnlyerror("u1", "用户名已存在!");
Map<String,String> error=BeanJ.getErrors();
request.setAttribute("tips", error);
request.getRequestDispatcher("/index2.jsp").forward(request, response);
return ;
}
if(sql_Datrilla.ZengShanGai_insert_delete_update(sqlYuJu))
{
this.getServletContext().setAttribute( "XiaoXi","注册成功");
//result=(String)this.getServletContext().getAttribute("XiaoXi");
response.sendRedirect("index.jsp") ;
}
}catch(Exception err)
{
System.out.println("数据库载入异常");
err.printStackTrace();
System.exit(0);
}
}
}
package login;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Enumeration;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jianYan.ZhuCe;
import sqlXueChe.MingLing_CMD;
/**
* Servlet implementation class Updateperson
*/
@WebServlet("/Updateperson")
public class Updateperson extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Updateperson() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
this.getServletContext().setAttribute( "XiaoXi","");
ZhuCe BeanJ=new ZhuCe();
try
{
Enumeration<String> me = request.getParameterNames();
while(me.hasMoreElements())
{
String name = (String) me.nextElement();
String value = request.getParameter(name);
BeanJ.setValue(name, value);
}
}catch(Exception err)
{
System.out.println("wrong_index2");
err.printStackTrace();
System.exit(0);
//throw new RuntimeException(err);
}
if(BeanJ.validate_ZhuCe()==false)
{
System.out.println("input_error");
Map<String,String> error=BeanJ.getErrors();
request.setAttribute("tips", error);
request.getRequestDispatcher("/personal.jsp").forward(request, response);
return;
}
String sqlpro="select count(*)from 用户表 where 用户名=? and 用户编号<>? ";/*select查询*/
String sqlYuJu="update 用户表 set 用户名=?,密码=?,联系电话=?,电子邮箱=? ,备注=?,专业=?,出生日期=? where 用户编号=?";
try
{
String QuDong_JDriver=this.getServletContext().getInitParameter("QuDong_JDriver");
String YongHu_user=this.getServletContext().getInitParameter("YongHu_user");
String MiMa_password=this.getServletContext().getInitParameter("MiMa_password");
String SJKDiZhi_url=this.getServletContext().getInitParameter("SJKDiZhi_url");
MingLing_CMD sql_Datrilla=new MingLing_CMD(QuDong_JDriver,SJKDiZhi_url,YongHu_user,MiMa_password);
HttpSession session = request.getSession();
String numberName=(String)session.getAttribute("username");
ResultSet rs = sql_Datrilla.ChaKan_select(sqlpro, BeanJ.getUsername(),numberName);
rs.next();
if(rs.getLong(1)>=1)
{
BeanJ.setOnlyerror("u1", "用户名已存在!");
Map<String,String> error=BeanJ.getErrors();
request.setAttribute("tips", error);
request.getRequestDispatcher("/personal.jsp").forward(request, response);
return ;
}
if(sql_Datrilla.ZengShanGai_insert_delete_update(sqlYuJu,
BeanJ.getUsername(),BeanJ.getPassword(),BeanJ.getphone(),
BeanJ.getsex(),BeanJ.getpostnum(),BeanJ.getdegree(),BeanJ.getyear(),numberName))
{
request.setAttribute("bea", BeanJ);
this.getServletContext().setAttribute( "XiaoXi","修改成功");
//result=(String)this.getServletContext().getAttribute("XiaoXi");
request.getRequestDispatcher("/personalsee.jsp").forward(request, response);
}
}catch(Exception err)
{
System.out.println("数据库载入异常");
err.printStackTrace();
System.exit(0);
}
}
}
package sqlXueChe;
import java.sql.* ;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
/*
* @Datrilla
* @date:2015-12-18
* @DAO(Data Access Object)是一个数据访问接口,数据访问
* @DBDAO数据库连接池
* */
public class MingLing_CMD {
private String QuDong_JDriver=null;
private Connection LianJie_con=null;
private String YongHu_user=null;
private String MiMa_password=null;
private String SJKDiZhi_url=null;
public MingLing_CMD()
{
}
public MingLing_CMD(String driver,String db)
{
this.QuDong_JDriver=driver;
this.SJKDiZhi_url=db;
}
public MingLing_CMD(String driver,String db,String user,String psw)
{
this.QuDong_JDriver=driver;
this.YongHu_user=user;
this.MiMa_password=psw;
this.SJKDiZhi_url=db;
}
/* @SearchBy:Datrilla
* @http://blog.sina.com.cn/s/blog_62148d1e0100hkqc.html
* 简单的说,如果一个方法中用了throws,那么这个方法会向上抛出一个异常,那么在调用这个方法的时候必须把这个调用放在try...catch块里处理这个异常。
* */
public Connection getCon()throws Exception
{
if(LianJie_con==null)
{
Class.forName(this.QuDong_JDriver);
if(this.MiMa_password!=null&&this.YongHu_user!=null)
this.LianJie_con=DriverManager.getConnection(this.SJKDiZhi_url,this.YongHu_user, this.MiMa_password);
else
this.LianJie_con=DriverManager.getConnection(this.SJKDiZhi_url);
}
return this.LianJie_con;
}
/* @SearchBy:Datrilla
* @By:BaiDu
* 只执行一次的SQL语句选择Statement是最好的.
* 相反,多次执行选用PreparedStatement是最好的
* 1. ResultSet executeQuery(String sql); 执行SQL查询,并返回ResultSet 对象。
* 2.int executeUpdate(String sql); 可执行增,删,改,返回执行受到影响的行数。
* 3. boolean execute(String sql); 可执行任何SQL语句,返回一个布尔值,表示是否返回
* */
public boolean ZengShanGai_insert_delete_update(String sql,Object...args)
throws Exception
{
PreparedStatement MingLing_stmt=getCon().prepareStatement(sql);
for(int i=0;i<args.length;i++)
MingLing_stmt.setObject(i+1, args[i]);
if(MingLing_stmt.executeUpdate()!=1)
return false;
return true;
}
public ResultSet ChaKan_select(String sql,Object...args)
throws Exception
{
PreparedStatement MingLing_stmt=getCon().prepareStatement(sql);
for(int i=0;i<args.length;i++)
MingLing_stmt.setObject(i+1, args[i]);
return MingLing_stmt.executeQuery();
}
public ResultSet ChunChu_produce(String sql,Object...args)
throws Exception
{
CallableStatement MingLing_stmt=getCon().prepareCall(sql);
for(int i=0;i<args.length;i++)
MingLing_stmt.setObject(i+1, args[i]);
return MingLing_stmt.executeQuery();
}
public void GuanBi_closecon()
throws Exception
{
if(this.LianJie_con!=null&&!this.LianJie_con.isClosed())
this.LianJie_con.close();
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="keywords" content="驾照 考试 驾校 driveschool 么么"/>
<style type="text/css">
.bodycenter
{
margin-left:300px;
}
p
{
color:red;
}
</style>
<title>你考驾照了么</title>
</head>
<body
style="background-position: top right; background-image: url('images/image3.jpg'); background-repeat: repeat; background-attachment: fixed;">
<div >
<div>
<!--横幅-->
<div style="background-color:#FFF;height:46px;weight:1349px">
<div style="backgroud-color:#FFFFFF;height:46px;opacity:1;" >
<!-- http://www.akuziti.com/ -->
<span style="weight:50px;height:10px;">
<img src="images/TiMu_title.png" style="height: 46px; width: 259px;float:left;"></img>
</span><p style="weight:10px;margin-top:15px;float:left;"></p>
</div>
</div>
<!--登入-->
<div class="bodycenter">
<form id="l1" method="post">
<table width="623" cellspacing="0" cellpadding="0" border="1" bordercolor="#FFFFFF"
height="164" style="width: 511px; " >
<tbody>
<tr>
<td colspan="2" align="center"
><font color="#FFFFFF">用户登入</font><br/>
<%
String msg =(String) application.getAttribute("XiaoXi");
%>
<%
msg=msg==null?(String)request.getAttribute("meg"):msg;
%>
<p> <%=(msg==null?"":msg) %></p>
</td>
</tr>
<tr>
<td align="right" > <font color="#FFFFFF">用户名:</font></td>
<td>
<input type="text" id="username" name="username" style="width: 154px; ">
</td>
</tr>
<tr>
<td align="right"><font color="#FFFFFF">密 码:</font></td>
<td>
<input type="password" id="password" name="password" style="width: 157px; "></td>
</tr>
<tr>
<td align="right" style="width: 177px;">
<input type="submit" value="登入"
style="background-image: url('images/image1.jpg');" onclick="fmesseage()"/>
</td>
<td align="center">
<input type="submit" value="注册" onclick="fm()"
style="background-image:url('images/image1.jpg');"></td>
</tr>
</tbody>
</table>
</form>
<script>
function fm()
{
var l1=document.getElementById("l1");
l1.action="<%=request.getContextPath()%>/index2.jsp";
l1.submit();
}
</script>
<script type="text/javascript">
function fmesseage()
{
var use=document.getElementById("username");
var mima=document.getElementById("password");
var l1=document.getElementById("l1");
if(use.value==""||use.value==null)
{
alert("用户名不能为空");
use.focus();
return ;
}
if(mima.value==""||mima.value==null)
{
alert("密码无效");
mima.focus();
return;
}
l1.action="<%=request.getContextPath()%>/Login1";
l1.submit();
}
</script>
</div>
</div>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page language="java" import="jianYan.ZhuCe" contentType="text/html; charset=UTF-8"%> <%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" ><title>注册页面</title><style type="text/css"> .bodycenter { margin-left:300px; }*{font-size:12px; margin:0; padding:0;} fieldset { padding:10px; margin:10px; width:400px; color:#333; border:#FFFFFF solid 1px border-radius:40px; -moz-border-radius:40px;} legend {color:#06c; font:24px; } ul {list-style-type: none; margin:40px auto;} #o { float:right; } p { color:red; } #kk { list-style-type:none; font:23px; } #kk>div /*子选择器使用了 > (子结合符)*/ { margin-top:2px; } #kk>div>div { font:25; height:26px; } button { height:30px; width:60px; } </style> </head> <body style="background-position: top right; background-image: url('images/image3.jpg'); background-repeat: repeat; background-attachment: fixed;" > <div> <!--横幅--> <div style="background-color:#FFF;height:46px;weight:1349px"> <div style="backgroud-color:#FFFFFF;height:46px;opacity:1;" ><!-- http://www.akuziti.com/ --><span style="weight:50px;height:10px;"><img src="images/TiMu_title.png" style="height: 46px; width: 259px;float:left;"></img> </span><p style="weight:10px;margin-top:15px;float:left;"></p> </div> </div> <div class="bodycenter"> <form id="l2" method="post"> <fieldset > <legend>个人信息</legend> <div id="kk"> <div><div>用户名</div> <div> <%---- 前提确认不会出现中文乱码;使用EL表达式${}提取存储在request对象中的tips对象中封装的表单数据(tips.p1)以及错误提示消息(tips.u1)--EL表达式的常用:--1、从表单提交到另一个页面,使用param( paramValues)例如:--Request.getParameter(“username”)可写成${param.usernam},${paramValues.hobby[2]}--2、从隐式对象中获取数据:例如:session.setAttribute(“hello”,”123”);--Sesson.getAttribute(“hello”);可写成${sessionScope.hello},获取javaBean中的数据,例如session.setAttribute(“user”,user);--User u=(User)Session.getAttribute(“user”);u.getUserName();--可为${sessionScope.user.userName}--当前面没有写隐式对象的时候,例如${ hello},编译器会自动从最小的默认对象开始找,即pageScope、requestScope、sessionScope、applicationScope,找到匹配的显示,没有找到则为null--EL的默认对象:--pageScope、requestScope、sessionScope、applicationScope、param、paramValues、header、headerValues、cookie、、--3、动态赋值:${sessionScope.user[data]},如果data为userSex,则它的值 为${sessionScope.user[“userSex”]}等价于${sessionScope.user.userSex},如果data的值 为userName,则它的值为${sessionScope.user.userName},用.的方式无法动态赋值--4、若要在页面显示El表达式,在EL表达式的前面加上一个反斜杠,例如:\${1.2+4.5} --%> <input id="username" name="username" type="text" value="<%if(request.getParameter("username")!=null){out.print(request.getParameter("username"));} %>"></input>${tips.u1} </div> </div> <div> <div>密码</div> <div><input type="password" id="password" type="text" name="password" value="<%if(request.getParameter("password")!=null){out.print(request.getParameter("password"));} %>"></input>${tips.p1}${tips.p2}</div> </div> <div><div>密码确认</div><div><input type="password" id="phonenumber" name="p1" type="text" value="<%if(request.getParameter("p1")!=null){out.print(request.getParameter("p1"));} %>"></input></div> </div> <div> <div>电子邮箱 </div><div><input id="sex" type="text" name="sex" value="<%if(request.getParameter("sex")!=null){out.print(request.getParameter("sex"));} %>"></input></div> </div> <div> <div>出生日期 <select id="year" name="year" onchange="changeday()"></select> <%String year=request.getParameter("year")!=null?new String(request.getParameter("year")):"1993";%>年 <select id="monthTime" name="monthTime" onchange="changeday()"></select> <%String monthTime=request.getParameter("monthTime")!=null?new String(request.getParameter("monthTime")):"1";%>月 <select id="day" name="day"></select> <%String day=request.getParameter("day")!=null?new String(request.getParameter("day")):"1";%>日${tips.y1} <script type="text/javascript" language="javascript"> //主要代码http://www.ok12.net/html/96.html var curdate = new Date(); var year = document.getElementById("year"); var month = document.getElementById("monthTime"); var day = document.getElementById("day"); //绑定年份月分的默认 function add() { var curyear = curdate.getFullYear(); var minyear = curyear - 80; var maxyear = curyear - 18; for (maxyear; maxyear >= minyear; maxyear = maxyear - 1) {//年份 year.options.add(new Option(maxyear, maxyear)); } var thisyear="<%=year%>"; year.value=thisyear; for (var mindex = 1; mindex <= 12; mindex++) {//月份 month.options.add(new Option(mindex, mindex)); } var thismonth="<%=monthTime%>"; month.value=thismonth; changeday(); } //判断是否是闰年 function leapyear(intyear) { return ((intyear % 400 == 0) ||((intyear % 4 == 0) && (intyear % 100 != 0)))?true:false; } //绑定天数 function addday(maxday) { //day.options.length = 1;这句话会增加一句空白选项 day.options.length = 0; for (var dindex = 1; dindex <= maxday; dindex++) { day.options.add(new Option(dindex, dindex)); } var thisday="<%=day%>"; thisday=thisday==null||(thisday!=null&&thisday>maxday)?"1":thisday; day.value=thisday; } function changeday() { if (year.value == null || year.value == "") { alert("请先选择年份!"); return false; } else { if (month.value == 1 || month.value == 3 || month.value == 5 || month.value == 7 || month.value == 8 || month.value == 10 || month.value == 12) { addday(31); } else { if (month.value == 4 || month.value == 6 || month.value == 9 || month.value == 11) { addday(30); } else { if (leapyear(year.value)) { addday(29); } else { addday(28); } } } } } window.onload = add; </script> </div> </div> <div><div> 联系电话</div><div><input id="phonenumber" name="phone" type="text" value="<%if(request.getParameter("phone")!=null){out.print(request.getParameter("phone"));} %>"></input></div> </div> <div> <div>备注</div> <div><input id="postnumber" name="postnum" type="text" value="<%if(request.getParameter("postnum")!=null){out.print(request.getParameter("postnum"));} %>"></input></div> </div> <div> <div>专业 </div><div><input id="identifyid" name="iden" type="text" value="<%if(request.getParameter("iden")!=null){out.print(request.getParameter("iden"));} %>"></input></div> </div> <div> <div> 学历 <select id="degree" name="degree" > <option>博士</option> <option>硕士</option> <option>本科</option> <option>专科</option> <option>高中</option> <option>初中</option> <option>小学</option> <option>幼儿园</option> </select> <%String str1=request.getParameter("degree")!=null?new String(request.getParameter("degree")):"博士";%> <script type="text/javascript"> //http://blog.sina.com.cn/s/blog_a5f093b401015b5r.html //new String(request.getParameter("degree").getBytes("iso-8859-1"), "utf-8") var dec=document.getElementById("degree"); var str="<%=str1%>"; //这里我用String就出不来 dec.value=str; //$("#degree option[text="+dec+"]").attr("selected", true); </script> </div> </div> <div> <div> <button id="ok" type="submit" onclick="subok22()" style="background-image:url('images/image1.jpg');" >注册 </button> <button id="o" type="submit" onclick="su22()" style="background-image:url('images/image1.jpg');">返回</button> </div> </div> </div> </fieldset> </form> </div> <script type="text/javascript"> <!-- function su22() { l2.action="<%=request.getContextPath()%>/index.jsp"; l2.submit(); } --> </script> <script type="text/javascript"> <!-- function subok22() { var use=document.getElementById("username"); var mima=document.getElementById("password"); var l2=document.getElementById("l2"); if(use.value==""||use.value==null) { alert("用户名不能为空"); thisdiv.username.focus(); return ; } if(mima.value==""||mima.value==null) { alert("密码无效"); thisdiv.password.focus(); return; } l2.action="<%=request.getContextPath()%>/Register"; l2.submit(); } --> </script> </div></body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language="java" import="jianYan.ZhuCe" contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>注册页面</title>
<style type="text/css">
.bodycenter
{
margin-left:300px;
}
*{font-size:12px; margin:0; padding:0;}
fieldset {
padding:10px;
margin:10px;
width:400px;
color:#333;
border:#FFFFFF solid 1px
border-radius:40px;
-moz-border-radius:40px;}
legend {color:#06c; font:24px; }
ul {list-style-type: none; margin:40px auto;}
#o
{
float:right;
}
p
{
color:red;
}
#kk {
list-style-type:none;
font:23px;
}
#kk>div /*子选择器使用了 > (子结合符)*/
{
margin-top:2px;
}
#kk>div>div
{
font:25;
height:26px;
}
button
{
height:30px;
width:60px;
}
</style>
</head>
<body style="background-position: top right; background-image: url('images/image3.jpg'); background-repeat: repeat; background-attachment: fixed;" >
<div>
<div class="bodycenter">
<form id="l2" method="post">
<fieldset >
<legend>个人信息</legend>
<div id="kk">
<div><div>用户名</div>
<div>
<%--
-- 前提确认不会出现中文乱码;使用EL表达式${}提取存储在request对象中的tips对象中封装的表单数据(tips.p1)以及错误提示消息(tips.u1)
--EL表达式的常用:
--1、从表单提交到另一个页面,使用param( paramValues)例如:
--Request.getParameter(“username”)可写成${param.usernam},${paramValues.hobby[2]}
--2、从隐式对象中获取数据:例如:session.setAttribute(“hello”,”123”);
--Sesson.getAttribute(“hello”);可写成${sessionScope.hello},获取javaBean中的数据,例如session.setAttribute(“user”,user);
--User u=(User)Session.getAttribute(“user”);u.getUserName();
--可为${sessionScope.user.userName}
--当前面没有写隐式对象的时候,例如${ hello},编译器会自动从最小的默认对象开始找,即pageScope、requestScope、sessionScope、applicationScope,找到匹配的显示,没有找到则为null
--EL的默认对象:
--pageScope、requestScope、sessionScope、applicationScope、param、paramValues、header、headerValues、cookie、、
--3、动态赋值:${sessionScope.user[data]},如果data为userSex,则它的值 为${sessionScope.user[“userSex”]}等价于${sessionScope.user.userSex},如果data的值 为userName,则它的值为${sessionScope.user.userName},用.的方式无法动态赋值
--4、若要在页面显示El表达式,在EL表达式的前面加上一个反斜杠,例如:\${1.2+4.5}
--%>
<input id="username" name="username" type="text"
value="<%if(request.getParameter("username")!=null){out.print(request.getParameter("username"));} %>"></input>${tips.u1}
</div>
</div>
<div>
<div>密码</div>
<div><input type="password" id="password" type="text" name="password"
value="<%if(request.getParameter("password")!=null){out.print(request.getParameter("password"));} %>"></input>${tips.p1}${tips.p2}</div>
</div>
<div><div>密码确认</div><div><input type="password" id="phonenumber" name="p1" type="text"
value="<%if(request.getParameter("p1")!=null){out.print(request.getParameter("p1"));} %>"></input></div>
</div>
<div> <div>电子邮箱 </div><div><input id="sex" type="text" name="sex"
value="<%if(request.getParameter("sex")!=null){out.print(request.getParameter("sex"));} %>"></input></div>
</div>
<div> <div>出生日期
<select id="year" name="year" onchange="changeday()"></select>
<%String year=request.getParameter("year")!=null?new String(request.getParameter("year")):"1993";%>年
<select id="monthTime" name="monthTime" onchange="changeday()"></select>
<%String monthTime=request.getParameter("monthTime")!=null?new String(request.getParameter("monthTime")):"1";%>月
<select id="day" name="day"></select>
<%String day=request.getParameter("day")!=null?new String(request.getParameter("day")):"1";%>日${tips.y1}
<script type="text/javascript" language="javascript">
//主要代码http://www.ok12.net/html/96.html
var curdate = new Date();
var year = document.getElementById("year");
var month = document.getElementById("monthTime");
var day = document.getElementById("day");
//绑定年份月分的默认
function add()
{
var curyear = curdate.getFullYear();
var minyear = curyear - 80;
var maxyear = curyear - 18;
for (maxyear; maxyear >= minyear; maxyear = maxyear - 1)
{//年份
year.options.add(new Option(maxyear, maxyear));
}
var thisyear="<%=year%>";
year.value=thisyear;
for (var mindex = 1; mindex <= 12; mindex++)
{//月份
month.options.add(new Option(mindex, mindex));
}
var thismonth="<%=monthTime%>";
month.value=thismonth;
changeday();
}
//判断是否是闰年
function leapyear(intyear)
{
return ((intyear % 400 == 0) ||((intyear % 4 == 0) && (intyear % 100 != 0)))?true:false;
}
//绑定天数
function addday(maxday)
{
//day.options.length = 1;这句话会增加一句空白选项
day.options.length = 0;
for (var dindex = 1; dindex <= maxday; dindex++) {
day.options.add(new Option(dindex, dindex));
}
var thisday="<%=day%>";
thisday=thisday==null||(thisday!=null&&thisday>maxday)?"1":thisday;
day.value=thisday;
}
function changeday()
{
if (year.value == null || year.value == "") {
alert("请先选择年份!");
return false;
}
else {
if (month.value == 1 || month.value == 3 || month.value == 5 || month.value == 7 || month.value == 8 || month.value == 10 || month.value == 12) {
addday(31);
}
else {
if (month.value == 4 || month.value == 6 || month.value == 9 || month.value == 11) {
addday(30);
}
else {
if (leapyear(year.value)) {
addday(29);
}
else {
addday(28);
}
}
}
}
}
window.onload = add;
</script>
</div>
</div>
<div>
<div> 联系电话</div><div><input id="phonenumber" name="phone" type="text"
value="<%if(request.getParameter("phone")!=null){out.print(request.getParameter("phone"));} %>"></input></div>
</div>
<div>
<div>备注</div>
<div><input id="postnumber" name="postnum" type="text"
value="<%if(request.getParameter("postnum")!=null){out.print(request.getParameter("postnum"));} %>"></input></div>
</div>
<div>
<div>专业 </div><div><input id="identifyid" name="iden" type="text"
value="<%if(request.getParameter("iden")!=null){out.print(request.getParameter("iden"));} %>"></input></div>
</div>
<div>
<div>
学历 <select id="degree" name="degree"
>
<option>博士</option>
<option>硕士</option>
<option>本科</option>
<option>专科</option>
<option>高中</option>
<option>初中</option>
<option>小学</option>
<option>幼儿园</option>
</select>
<%String str1=request.getParameter("degree")!=null?new String(request.getParameter("degree")):"博士";%>
<script type="text/javascript">
//http://blog.sina.com.cn/s/blog_a5f093b401015b5r.html
//new String(request.getParameter("degree").getBytes("iso-8859-1"), "utf-8")
var dec=document.getElementById("degree");
var str="<%=str1%>"; //这里我用String就出不来
dec.value=str;
//$("#degree option[text="+dec+"]").attr("selected", true);
</script>
</div>
</div>
<div>
<div>
<button id="ok" type="submit" onclick="subok22()" style="background-image:url('images/image1.jpg');" >确认修改
</button>
<button id="o" type="submit" onclick="su22()" style="background-image:url('images/image1.jpg');">返回</button>
</div>
</div>
</div>
</fieldset>
</form>
</div>
<script type="text/javascript">
<!--
function su22()
{
l2.action="<%=request.getContextPath()%>/personalsee.jsp";
l2.submit();
}
-->
</script>
<script type="text/javascript">
<!--
function subok22()
{
var use=document.getElementById("username");
var mima=document.getElementById("password");
var l2=document.getElementById("l2");
if(use.value==""||use.value==null)
{
alert("用户名不能为空");
thisdiv.username.focus();
return ;
}
if(mima.value==""||mima.value==null)
{
alert("密码无效");
thisdiv.password.focus();
return;
}
l2.action="<%=request.getContextPath()%>/Updateperson";
l2.submit();
}
-->
</script>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language="java" import="jianYan.ZhuCe" contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>注册页面</title>
<style type="text/css">
.bodycenter
{
margin-left:300px;
}
*{font-size:12px; margin:0; padding:0;}
fieldset {
padding:10px;
margin:10px;
width:400px;
color:#333;
border:#FFFFFF solid 1px
border-radius:40px;
-moz-border-radius:40px;}
legend {color:#06c; font:24px; }
ul {list-style-type: none; margin:40px auto;}
#o
{
float:right;
}
p
{
color:red;
}
#kk {
list-style-type:none;
font:23px;
}
#kk>div /*子选择器使用了 > (子结合符)*/
{
margin-top:2px;
}
#kk>div>div
{
font:25;
height:26px;
}
button
{
height:30px;
width:60px;
}
</style>
</head>
<body style="background-position: top right; background-image: url('images/image3.jpg'); background-repeat: repeat; background-attachment: fixed;" >
<div>
<div class="bodycenter">
<fieldset >
<legend>个人信息</legend>
<div id="kk">
<form id="per" method="post" >
<div>用户名: ${bea.username}</div>
<%--
-- 前提确认不会出现中文乱码;使用EL表达式${}提取存储在request对象中的tips对象中封装的表单数据(tips.p1)以及错误提示消息(tips.u1)
--EL表达式的常用:
--1、从表单提交到另一个页面,使用param( paramValues)例如:
--Request.getParameter(“username”)可写成${param.usernam},${paramValues.hobby[2]}
--2、从隐式对象中获取数据:例如:session.setAttribute(“hello”,”123”);
--Sesson.getAttribute(“hello”);可写成${sessionScope.hello},获取javaBean中的数据,例如session.setAttribute(“user”,user);
--User u=(User)Session.getAttribute(“user”);u.getUserName();
--可为${sessionScope.user.userName}
--当前面没有写隐式对象的时候,例如${ hello},编译器会自动从最小的默认对象开始找,即pageScope、requestScope、sessionScope、applicationScope,找到匹配的显示,没有找到则为null
--EL的默认对象:
--pageScope、requestScope、sessionScope、applicationScope、param、paramValues、header、headerValues、cookie、、
--3、动态赋值:${sessionScope.user[data]},如果data为userSex,则它的值 为${sessionScope.user[“userSex”]}等价于${sessionScope.user.userSex},如果data的值 为userName,则它的值为${sessionScope.user.userName},用.的方式无法动态赋值
--4、若要在页面显示El表达式,在EL表达式的前面加上一个反斜杠,例如:\${1.2+4.5}
--%>
<div>电子邮箱:${bea.sex}</div>
<div>出生日期:${bea.year}</div>
<div> 联系电话:${bea.phone}</div>
<div>备注:${bea.postnum}</div>
<div> 学历 :${bea.degree}</div>
</form>
<div>
<button id="xiug" type="submit" onclick="xiug()" style="background-image:url('images/image1.jpg');" >修改信息
</button>
</div>
</div>
</fieldset>
</div>
<script type="text/javascript">
<!--
function xiug()
{
window.location.href="personal.jsp";
}
-->
</script>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title><style type="text/css">
.bodycenter
{
margin:20px auto auto auto;
}
.guide-bar
{
font-size:18px;
font-weight:normal;
height:46px;
display:block;
color:#706f6f;
padding:0 5px;
float:left;
position:relative;
margin:19px 12px 0 0;
line-heigth:46px;
border-radius:6px;
}
a {
text-decoration:none;
color:#0F0110;
}
a:hover
{
color:#FFC0CB;
}
a.active
{
color:#FFC0C9;
cursor:wait;
}
button
{
height:30px;
}
.youbian
{
float:right;
}
</style>
</head>
<body
style="background-position: top right; background-image: url('images/image3.jpg'); background-repeat: repeat; background-attachment: fixed;">
<div >
<div>
<!--横幅-->
<div style="background-color:#FFF;height:46px;weight:1349px">
<div style="backgroud-color:#FFFFFF;height:46px;opacity:1;" >
<!-- http://www.akuziti.com/ -->
<span style="weight:50px;height:10px;">
<img src="images/TiMu_title.png" style="height: 46px; width: 259px;float:left;"></img>
</span>
<p style="weight:10px;margin-top:15px;float:left;"> </p>
<div style="weight:10px" >
<div class="guide-bar">
<a href="dsmesseage.jsp" target="changekuang">驾校信息</a>|
<a href="load01" target="changekuang">个人信息</a>|
<a href="dsmesseage.jsp" target="changekuang">知识要点</a>|
<a href="wordtest.jsp" target="changekuang">文字模式</a>|
<a href="graphy.jsp" target="changekuang">图片模式</a>
</div>
</div>
<form id="hh" method="post" ></form>
<div><button class="youbian" onclick="outuser()" style="background-image:url('images/image1.jpg');">退出系统</button></div>
<script type="text/javascript">
<!--
function outuser()
{
var hh=document.getElementById("hh");
hh.action="<%=request.getContextPath()%>/GoOut";
hh.submit();
}
-->
</script>
</div>
</div>
<!--框架-->
<div class="bodycenter">
<iframe name="changekuang" style="display" src="dsmesseage.jsp" marginheight="0" marginwidth="0" frameborder="1" scrolling="no" width="1000px" height="1260px" >
#document
</iframe>
</div>
</div>
</div>
<script>
</script>
</body>
</html>
配置文件
java Dynamic Web Project + SQL
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>XueChe</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!--中文乱码统一处理器-->
<filter>
<filter-name>jianYan2</filter-name>
<filter-class>jianYan.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jianYan2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--是否登入校验器-->
<filter>
<filter-name>jianYan</filter-name>
<filter-class>jianYan.JiaoYanQi</filter-class>
</filter>
<filter-mapping>
<filter-name>jianYan</filter-name>
<url-pattern>/dsmesseage.jsp</url-pattern>
<url-pattern>/graphy.jsp</url-pattern>
<url-pattern>/personal.jsp</url-pattern>
<url-pattern>/personalsee.jsp</url-pattern>
<url-pattern>/XueHome.jsp</url-pattern>
<url-pattern>/wordtest.jsp</url-pattern>
</filter-mapping>
<!--个人信息是否已经获取检验器-->
<filter>
<filter-name>person</filter-name>
<filter-class>jianYan.Person</filter-class>
</filter>
<filter-mapping>
<filter-name>person</filter-name>
<url-pattern>/personload.*</url-pattern>
</filter-mapping>
<!--全局变量-->
<context-param>
<param-name>XinXi</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>XiaoXi</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>QuDong_JDriver</param-name>
<param-value>com.microsoft.sqlserver.jdbc.SQLServerDriver</param-value>
</context-param>
<context-param>
<param-name>SJKDiZhi_url</param-name>
<param-value>jdbc:sqlserver://127.0.0.1:1433;DatabaseName=database20152</param-value>
</context-param>
<context-param>
<param-name>YongHu_user</param-name>
<param-value>sqluser一</param-value>
</context-param>
<context-param>
<param-name>MiMa_password</param-name>
<param-value>sqltest123</param-value>
</context-param>
<!--提取个人信息servlet-->
<servlet>
<servlet-name>load11</servlet-name>
<servlet-class>login.Personload</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>load11</servlet-name>
<url-pattern>/load01</url-pattern>
</servlet-mapping>
<!--更新个人信息servlet-->
<servlet>
<servlet-name>pda</servlet-name>
<servlet-class>login.Updateperson</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>pda</servlet-name>
<url-pattern>/tpp</url-pattern>
</servlet-mapping>
<!--退出servlet-->
<servlet>
<servlet-name>tuichu</servlet-name>
<servlet-class>login.GoOut</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tuichu</servlet-name>
<url-pattern>/ttt</url-pattern>
</servlet-mapping>
<!--注册servlet-->
<servlet>
<servlet-name>login22</servlet-name>
<servlet-class>login.Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login22</servlet-name>
<url-pattern>/Fuwu2</url-pattern>
</servlet-mapping>
<!--主页登入servlet-->
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login.Login1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/Fuwu1</url-pattern>
</servlet-mapping>
</web-app>
其实两个配置文件的区别就在那个全局变量的数据库字符串那边
java Dynamic Web Project + MYSQL
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>XueChe</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!--中文乱码统一处理器-->
<filter>
<filter-name>jianYan2</filter-name>
<filter-class>jianYan.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jianYan2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--是否登入校验器-->
<filter>
<filter-name>jianYan</filter-name>
<filter-class>jianYan.JiaoYanQi</filter-class>
</filter>
<filter-mapping>
<filter-name>jianYan</filter-name>
<url-pattern>/dsmesseage.jsp</url-pattern>
<url-pattern>/graphy.jsp</url-pattern>
<url-pattern>/personal.jsp</url-pattern>
<url-pattern>/personalsee.jsp</url-pattern>
<url-pattern>/XueHome.jsp</url-pattern>
<url-pattern>/wordtest.jsp</url-pattern>
</filter-mapping>
<!--个人信息是否已经获取检验器-->
<filter>
<filter-name>person</filter-name>
<filter-class>jianYan.Person</filter-class>
</filter>
<filter-mapping>
<filter-name>person</filter-name>
<url-pattern>/personload.*</url-pattern>
</filter-mapping>
<!--全局变量-->
<context-param>
<param-name>XinXi</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>XiaoXi</param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>QuDong_JDriver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</context-param>
<context-param>
<param-name>SJKDiZhi_url</param-name>
<param-value>jdbc:mysql://localhost:3306/database20152</param-value>
</context-param>
<context-param>
<param-name>YongHu_user</param-name>
<param-value>sqluser1</param-value>
</context-param>
<context-param>
<param-name>MiMa_password</param-name>
<param-value>sqltest123</param-value>
</context-param>
<!--提取个人信息servlet-->
<servlet>
<servlet-name>load11</servlet-name>
<servlet-class>login.Personload</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>load11</servlet-name>
<url-pattern>/load01</url-pattern>
</servlet-mapping>
<!--更新个人信息servlet-->
<servlet>
<servlet-name>pda</servlet-name>
<servlet-class>login.Updateperson</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>pda</servlet-name>
<url-pattern>/tpp</url-pattern>
</servlet-mapping>
<!--退出servlet-->
<servlet>
<servlet-name>tuichu</servlet-name>
<servlet-class>login.GoOut</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tuichu</servlet-name>
<url-pattern>/ttt</url-pattern>
</servlet-mapping>
<servlet>
<!--注册servlet-->
<servlet-name>login22</servlet-name>
<servlet-class>login.Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login22</servlet-name>
<url-pattern>/Fuwu2</url-pattern>
</servlet-mapping>
<!--主页登入servlet-->
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login.Login1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/Fuwu1</url-pattern>
</servlet-mapping>
</web-app>