基于jsp的企业人事管理系统
图中BussinessObject是业务对象,是使用DAO模式的客户端;DataTransferObject数据传输对象,在应用程序不同层次之间传输对象,在一个分布式应用程序中,通常可以提高整理的性能;DataObjectAcces数据输入/输出对象封装了对数据源的一些基本操作;DataSource指的是数据源。可以从图中看出,DAO模式分离了业务逻辑和数据罗即将,是的编写的软件具有良好的层次式体系结构。本系统为了方便数据库的操作,主要使用DBContent的对象来接一个数据库(建立一个类DBContent),代码如下: public DBContent(){
String CLASSFORNAME=\连接数据库的驱动 String url=\
jdbc:microsoft:sqlserver://localhost:1433;databaseName=db_bangong \ String user=\连接数据库的用户名 String password=\连接数据库的密码 try{
Class.forName(CLASSFORNAME);
con= DriverManager.getConnection(url,user,password);//加载数据库的驱动 stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); }
catch(Exception ex){
ex.printStackTrace(); } }
在程序需要连接数据库的地方,只需要生成一个DBConnet的对象,就可以对数据库进行连接并操作。
3.2中文乱码问题处理
在程序中经常会遇到中文乱码的情况,如果手动的在servlet和jsp页面进行设置,相当麻烦。因此,在程序的开始就写了一个过滤器SetCharacterEncodingFilter。
在web.xml中配置:
基于jsp的企业人事管理系统
对应的SetCharacterEncodingFilter.java文件中的重要代码,在初始化init()方法中定义:
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter(\ String value = filterConfig.getInitParameter(\ }
在工具包util包中同样定义了DataFormate类来处理字符转换: public static String toUni(String gbStr){
String uniStr = \把字符串转换成uincode编码*/ if(gbStr == null){ gbStr = \ } try{
byte[] tempByte = gbStr.getBytes(\ uniStr = new String(tempByte,\ }catch(Exception ex){ }
return uniStr; }
/* 把字符串转换成Utf8编码*/
public static String toUtf8String(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i);
if (c >= 0 && c <= 255) { sb.append(c); } else {
byte[] b; try {
b = Character.toString(c).getBytes(\ }catch (Exception ex) { System.out.println(ex); b = new byte[0]; }
for (int j = 0; j < b.length; j++) { int k = b[j]; if (k < 0) {
基于jsp的企业人事管理系统
k += 256; }
sb.append(\ toUpperCase()); } } return sb.toString(); } }
基于jsp的企业人事管理系统
第四章 系统功能实现
在管理信息系统的生命周期中,仅过了需求分析、系统设计等阶段之后,便开始了系统实施阶段。在系统分析和设计阶段,系统开发工作主要是集中在逻辑、功能和技术设计上,系统实施阶段要继承此前面各个阶段的工作成果,将技术设计转化为物理实现,因此系统实施的成果是系统分析和设计阶段的结晶。
4.1系统登陆页面实现
1.描述:为了保证系统的安全性,要先使用本系统必须先登陆到系统中,并且不同角色的用户进入不同的界面,功能也随之不同。
2.程序运行效果图如图4.1所示:
图4.1 系统登陆页面设计
3.在登陆页面输入用户名和密码以,选择登陆身份后,点击提交按钮,跳转到登陆的service中,在该service中会对用户名,密码,验证码进行判断,并根据相应的用户角色进入对应的页面,loginservice关键代码:
public String login(String userName,String userPw,int userType) {
System.out.println(\ try {
Thread.sleep(700);
} catch (InterruptedException e) {
基于jsp的企业人事管理系统
// TODO Auto-generated catch block e.printStackTrace(); }
String result=\
if(userType==0)//系统管理员登陆 {
String sql=\ Object[] params={userName,userPw}; DB mydb=new DB();
mydb.doPstm(sql, params); try {
ResultSet rs=mydb.getRs();
boolean mark=(rs==null||!rs.next()?false:true); if(mark==false) {
result=\ } else {
result=\
TAdmin admin=new TAdmin();
admin.setUserId(rs.getInt(\
admin.setUserName(rs.getString(\ admin.setUserPw(rs.getString(\ WebContext ctx = WebContextFactory.get(); HttpSession session=ctx.getSession(); session.setAttribute(\ session.setAttribute(\ }
rs.close(); }
catch (SQLException e) {
System.out.println(\登录失败!\ e.printStackTrace(); }
finally {
mydb.closed(); }