Web应用——驾培管理系统之登录功能

      本节博文将向大家介绍本次驾培管理系统的登录功能。从创建一个对应数据表的bean开始,到界面填入参数,后台判断,传值,并且实现页面渲染,通过登录这一基础功能向大家展示这一流程,以供像我一样的初学者们学习。

首先来看结果图



首先是数据库所创建的用户表格t_user:



然后是数据库所有权限的表格t_function:



最后是数据库对应用户所拥有权限的表格t_user_function:




其次,是org.great.bean包下用户表t_user对应的UserBean

[java]  view plain  copy
  1. package org.great.bean;  
  2.   
  3. public class UserBean {  
  4.     private int user_id;  
  5.     private int role_id;  
  6.     private int driving_id;  
  7.     private String user_lname;  
  8.     private String user_pwd;  
  9.     private String user_name;  
  10.     private String user_sex;  
  11.     private String user_status;  
  12.     private String createtime;  
  13.     private String tel;  
  14.     private String driving_name;  
  15.       
  16.     public String getDriving_name() {  
  17.         return driving_name;  
  18.     }  
  19.     public void setDriving_name(String drivingName) {  
  20.         driving_name = drivingName;  
  21.     }  
  22.     public int getUser_id() {  
  23.         return user_id;  
  24.     }  
  25.     public void setUser_id(int userId) {  
  26.         user_id = userId;  
  27.     }  
  28.     public int getRole_id() {  
  29.         return role_id;  
  30.     }  
  31.     public void setRole_id(int roleId) {  
  32.         role_id = roleId;  
  33.     }  
  34.     public String getUser_lname() {  
  35.         return user_lname;  
  36.     }  
  37.     public void setUser_lname(String userLname) {  
  38.         user_lname = userLname;  
  39.     }  
  40.     public String getUser_pwd() {  
  41.         return user_pwd;  
  42.     }  
  43.     public void setUser_pwd(String userPwd) {  
  44.         user_pwd = userPwd;  
  45.     }  
  46.     public String getUser_name() {  
  47.         return user_name;  
  48.     }  
  49.     public void setUser_name(String userName) {  
  50.         user_name = userName;  
  51.     }  
  52.     public String getUser_sex() {  
  53.         return user_sex;  
  54.     }  
  55.     public void setUser_sex(String userSex) {  
  56.         user_sex = userSex;  
  57.     }  
  58.     public String getUser_status() {  
  59.         return user_status;  
  60.     }  
  61.     public void setUser_status(String userStatus) {  
  62.         user_status = userStatus;  
  63.     }  
  64.     public String getCreatetime() {  
  65.         return createtime;  
  66.     }  
  67.     public void setCreatetime(String createtime) {  
  68.         this.createtime = createtime;  
  69.     }  
  70.     public int getDriving_id() {  
  71.         return driving_id;  
  72.     }  
  73.     public void setDriving_id(int drivingId) {  
  74.         driving_id = drivingId;  
  75.     }  
  76.     public String getTel() {  
  77.         return tel;  
  78.     }  
  79.     public void setTel(String tel) {  
  80.         this.tel = tel;  
  81.     }  
  82.        
  83.       
  84.       
  85. }  


权限表t_function对应的FuncBean:

[java]  view plain  copy
  1. package org.great.bean;  
  2.   
  3. public class FuncBean {  
  4.     private int func_id;  
  5.     private int func_pid;  
  6.     private String func_name;  
  7.     private String func_url;  
  8.     private String func_level;  
  9.     private String func_tag;  
  10.     public int getFunc_id() {  
  11.         return func_id;  
  12.     }  
  13.     public void setFunc_id(int funcId) {  
  14.         func_id = funcId;  
  15.     }  
  16.     public int getFunc_pid() {  
  17.         return func_pid;  
  18.     }  
  19.     public void setFunc_pid(int funcPid) {  
  20.         func_pid = funcPid;  
  21.     }  
  22.     public String getFunc_name() {  
  23.         return func_name;  
  24.     }  
  25.     public void setFunc_name(String funcName) {  
  26.         func_name = funcName;  
  27.     }  
  28.     public String getFunc_url() {  
  29.         return func_url;  
  30.     }  
  31.     public void setFunc_url(String funcUrl) {  
  32.         func_url = funcUrl;  
  33.     }  
  34.     public String getFunc_level() {  
  35.         return func_level;  
  36.     }  
  37.     public void setFunc_level(String funcLevel) {  
  38.         func_level = funcLevel;  
  39.     }  
  40.     public String getFunc_tag() {  
  41.         return func_tag;  
  42.     }  
  43.     public void setFunc_tag(String funcTag) {  
  44.         func_tag = funcTag;  
  45.     }  
  46.       
  47.       
  48. }  


然后是org.great.dao包下创建UserDao类,并且创建一个工厂类,控制单例,使之每次只实例化一个Dao

UserDao类:

[java]  view plain  copy
  1. public interface UserDao {  
  2.     /**根据登录名查找用户信息*/  
  3.     public UserBean findUser_ByLname(String lname);  
  4. }  

DaoFactory类:

[java]  view plain  copy
  1. public class DaoFactory {  
  2.     private static UserDao userDao = null;  
  3.     private static FuncDao funcDao = null;  
[java]  view plain  copy
  1. <span style="white-space:pre">    </span>public static FuncDao getFuncDao(){  
  2. <span style="white-space:pre">        </span>if(funcDao == null){  
  3. <span style="white-space:pre">            </span>funcDao = new FuncDaoImpl();  
  4. <span style="white-space:pre">        </span>}  
  5. <span style="white-space:pre">        </span>return funcDao;  
  6. <span style="white-space:pre">    </span>}  
[java]  view plain  copy
  1.     public static UserDao getUserDao(){  
  2.         if(userDao == null){  
  3.             userDao = new UserDaoImpl();  
  4.         }  
  5.         return userDao;  
  6.     }  
  7.   
  8.       
  9. }  


FuncDaoImpl实现类对应进行数据库查询操作:

[java]  view plain  copy
  1. private PreparedStatement pre =  null;  
  2.     private ResultSet rs = null;  
  3.       
  4.     /** 获得权限表全部数据*/  
  5.     public List<FuncBean> getFunc_ALL(int user_id){  
  6.         List<FuncBean> list = new ArrayList<FuncBean>();  
  7.         Connection conn = DBUtils.getConn();  
  8.         String sql = "select f.func_id,f.func_pid,f.func_name,f.func_url,f.func_level from t_function f," +  
  9.                 "t_user_function rf where f.func_id = rf.func_id and rf.user_id = ?";  
  10.         try {  
  11.             pre = conn.prepareStatement(sql);  
  12.             pre.setInt(1, user_id);  
  13.             rs = pre.executeQuery();  
  14.             while(rs.next()){  
  15.                 FuncBean funcBean = new FuncBean();  
  16.                 funcBean.setFunc_id(rs.getInt(1));  
  17.                 funcBean.setFunc_pid(rs.getInt(2));  
  18.                 funcBean.setFunc_name(rs.getString(3));  
  19.                 funcBean.setFunc_url(rs.getString(4));  
  20.                 funcBean.setFunc_level(rs.getString(5));  
  21.                 list.add(funcBean);  
  22.             }  
  23.         } catch (SQLException e) {  
  24.             // TODO Auto-generated catch block  
  25.             e.printStackTrace();  
  26.         } finally{  
  27.             DBUtils.close(conn, pre, rs);  
  28.         }  
  29.           
  30.         return list;  
  31.     }  

UserDaoImpl实现类对应的数据库查询操作:

[java]  view plain  copy
  1. private PreparedStatement pre = null;  
  2.     private ResultSet rs = null;  
  3.     public UserBean findUser_ByLname(String lname) {  
  4.   
  5.         Connection conn = DBUtils.getConn();  
  6.         UserBean userBean = null;  
  7.         String sql = "select user_id,role_id,user_lname,user_pwd,user_name,user_sex,user_status," +  
  8.                 "createtime,driving_id,tel from t_user where user_lname = ? and user_status!='D'" ;  
  9.         try {  
  10.             pre = conn.prepareStatement(sql);  
  11.             pre.setString(1, lname);  
  12.             rs = pre.executeQuery();              
  13.               
  14.             if(rs.next()){  
  15.                 userBean = new UserBean();  
  16.                 userBean.setUser_id(rs.getInt(1));  
  17.                 userBean.setRole_id(rs.getInt(2));  
  18.                 userBean.setUser_lname(rs.getString(3));  
  19.                 userBean.setUser_pwd(rs.getString(4));  
  20.                 userBean.setUser_name(rs.getString(5));  
  21.                 userBean.setUser_sex(rs.getString(6));  
  22.                 userBean.setUser_status(rs.getString(7));  
  23.                 userBean.setCreatetime(rs.getString(8));  
  24.                 userBean.setDriving_id(rs.getInt(9));  
  25.                 userBean.setTel(rs.getString(10));  
  26.             }  
  27.         } catch (SQLException e) {  
  28.             e.printStackTrace();  
  29.         } finally{  
  30.             DBUtils.close(conn, pre, rs);  
  31.         }  
  32.         return userBean;  
  33.       
  34.     }  


org.great.servlet包下的登录判断的Servlet类:LoginServlet

[java]  view plain  copy
  1. public class LoginServlet extends HttpServlet{  
  2.     @Override  
  3.     protected void service(HttpServletRequest req, HttpServletResponse resp)  
  4.             throws ServletException, IOException {  
  5.   
  6.         req.setCharacterEncoding("utf-8");  
  7.         resp.setContentType("text/html;charset=utf-8");  
  8.           
  9.         String task = req.getParameter("task");  
  10.         if(null == task){  
  11.             req.setAttribute("msg""请先登录!");  
  12.             req.getRequestDispatcher("index.jsp").forward(req, resp);  
  13.         }else if(task.equals("login")){       
  14.             String userlname = req.getParameter("userlname");  
  15.             String userpwd = req.getParameter("userpwd");  
  16.             if("".equals(userlname)|| "".equals(userpwd)){  
  17.                 req.setAttribute("msg","用户名或密码不能为空!");  
  18.                 req.getRequestDispatcher("index.jsp").forward(req, resp);  
  19.             }else {  
  20.                 System.out.println("task--111"+task);  
  21.                 UserDao userDao = DaoFactory.getUserDao();  
  22.                 //通过登录账户名获取用户信息  
  23.                 UserBean userBean = userDao.findUser_ByLname(userlname);  
  24.                 if(null==userBean){  
  25.                     req.setAttribute("msg""用户名不存在");  
  26.                     req.getRequestDispatcher("index.jsp").forward(req, resp);  
  27.                 }else if(!userpwd.equals(userBean.getUser_pwd())){  
  28.                     req.setAttribute("msg""密码输入错误");  
  29.                     req.getRequestDispatcher("index.jsp").forward(req, resp);  
  30.                 }else if(userBean.getRole_id()==3||userBean.getRole_id()==4){  
  31.                     req.setAttribute("msg""抱歉,您没有权限登录");  
  32.                     req.getRequestDispatcher("index.jsp").forward(req, resp);  
  33.                 }else{    
  34.                     //列出权限->左侧导航栏  
  35.                     HttpSession session = req.getSession();  
  36.                     FuncDao funcDao = DaoFactory.getFuncDao();  
  37.                     List<FuncBean> funcBeans = funcDao.getFunc_ALL(userBean.getUser_id());  
  38.                     session.setAttribute("funcs", funcBeans);  
  39.                     session.setAttribute("Logindo", userBean);  
  40.                     session.setAttribute("funcDao", funcDao);  
  41.                     resp.sendRedirect("jsp/main/index.jsp");  
  42.                 }  
  43.             }  
  44.         }     
  45.     }  
  46. }  

WebRoot/index.jsp,项目初始页面(登录页面)

[html]  view plain  copy
  1. <%@ page language="<a href="http://lib.csdn.net/base/17" class="replace_word" title="Java EE知识库" target="_blank" style="color:#df3434; font-weight:bold;">java</a>import="java.util.*" pageEncoding="utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'index.jsp' starting page</title>  
  13.     <meta http-equiv="pragma" content="no-cache">  
  14.     <meta http-equiv="cache-control" content="no-cache">  
  15.     <meta http-equiv="expires" content="0">      
  16.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  17.     <meta http-equiv="description" content="This is my page">  
  18.     <!-- 
  19.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  20.     -->  
  21.     <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />  
  22.     <script type="text/<a href="http://lib.csdn.net/base/18" class="replace_word" title="JavaScript知识库" target="_blank" style="color:#df3434; font-weight:bold;">javascript</a>src="<%=basePath%>/<a href="http://lib.csdn.net/base/22" class="replace_word" title="jQuery知识库" target="_blank" style="color:#df3434; font-weight:bold;">jquery</a>-2.1.4/jquery1.9.0.min.js"></script>  
  23.     <script type="text/javascript" src="<%=basePath%>/easyvalidator2/js/validate.pack.js">  
  24.     </script>  
  25.     <link href="<%=basePath%>/easyvalidator2/css/validate.css" rel="stylesheet" type="text/css" />  
  26.   </head>  
  27.   <body>  
  28.         <table width="100%">  
  29.             <!-- 顶部部分 -->  
  30.             <tr height="41"><td colspan="2" background="<%=basePath%>/background/Images/login_top_bg.gif"> </td></tr>  
  31.             <!-- 主体部分 -->  
  32.             <tr style="background:url(<%=basePath%>/background/Images/login_bg.jpg) repeat-x;" height="532">  
  33.                 <!-- 主体左部分 -->  
  34.                 <td id="left_cont">  
  35.                     <table width="100%" height="100%">  
  36.                         <tr height="155"><td colspan="2"> </td></tr>  
  37.                         <tr>  
  38.                             <td width="20%" rowspan="2"> </td>  
  39.                             <td width="60%">  
  40.                                 <table width="100%">  
  41.                                     <tr height="70"><td align="right"></td></tr>  
  42.                                     <tr height="274">  
  43.                                         <td valign="top" align="right">  
  44.                                             
  45.                                         </td>  
  46.                                     </tr>  
  47.                                 </table>  
  48.                             <td width="15%" rowspan="2"> </td>  
  49.                             </td>  
  50.                         </tr>  
  51.                         <tr><td colspan="2"> </td></tr>  
  52.                     </table>  
  53.                 </td>  
  54.                   
  55.                 <!-- 主体右部分 -->  
  56.                 <td id="right_cont">  
  57.                     <table height="100%">  
  58.                         <tr height="30%"><td colspan="3"> </td></tr>  
  59.                         <tr>  
  60.                             <td width="30%" rowspan="5"> </td>  
  61.                             <td valign="top" id="form">  
  62.                                 <form action="login.do" method="post">  
  63.                                     <table valign="top" width="50%">  
  64.                                         <tr><td colspan="2"><h4 style="letter-spacing:1px;font-size:16px;">驾校管理后台</h4></td></tr>  
  65.                                         <tr>  
  66.                                         <td>用户名:</td>  
  67.                                         <td>  
  68.                                         <input type="text" name="userlname" value="" />  
  69.                                         </td>  
  70.                                         </tr>  
  71.                                         <tr><td>密    码:</td><td><input type="password" name="userpwd" value="" />  
  72.                                         <input type="hidden" name="task" value="login">  
  73.                                         </td></tr>  
  74.                                           
  75.                                         <tr class="bt" align="center"><td> <input type="submit" value="登陆" /></td><td> <input type="reset" value="重填" /></td></tr>  
  76.                                     </table>  
  77.                                 </form>  
  78.                             </td>  
  79.                             <td rowspan="5"> </td>  
  80.                         </tr>  
  81.                         <tr><td colspan="3"> </td></tr>  
  82.                     </table>  
  83.                 </td>  
  84.             </tr>  
  85.             <!-- 底部部分 -->  
  86.             <tr id="login_bot"><td colspan="2"><p>Copyright © 2015-2016 ChuanYi AX1510工作室</p></td></tr>  
  87.         </table>  
  88.     </body>  
  89.     <script type="text/javascript">  
  90.       
  91.       var msg = "<%=request.getAttribute("msg")%>";  
  92.       if(msg!="null"){  
  93.         alert(msg);  
  94.       }  
  95.     </script>  
  96. </html>  

登录成功后跳转的Jsp:WebRoot/jsp/main/index.jsp,它包含了三个jsp,使用了frame框架

[html]  view plain  copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'index.jsp' starting page</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <!-- 
  20.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  21.     -->  
  22.   
  23.   </head>  
  24.     
  25.   <frameset rows="64,*"  frameborder="no" border="0" framespacing="0">  
  26.     <!--头部-->  
  27.     <frame src="<%=basePath%>/jsp/main/top.jsp" name="top" noresize="noresize" frameborder="0"  scrolling="no" marginwidth="0" marginheight="0" />  
  28.     <!--主体部分-->  
  29.     <frameset cols="185,*">  
  30.         <!--主体左部分-->  
  31.         <frame src="<%=basePath%>/jsp/main/left.jsp" name="left" noresize="noresize" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" />  
  32.         <!--主体右部分-->  
  33.         <frame src="<%=basePath%>/jsp/main/main.jsp" name="main" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" />  
  34. </frameset>  
  35. </html>  

top.jsp

[html]  view plain  copy
  1. <%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'top.jsp' starting page</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />  
  20.     <script type="text/javascript">  
  21.         function logout() {  
  22.             if(window.confirm('您确定要退出吗?')) {  
  23.                   
  24.                 top.location = 'user.do?task=logout';  
  25.                   
  26.             }  
  27.         }         
  28.     </script>  
  29.   
  30.   </head>  
  31.     
  32.   <body>  
  33.         <table cellpadding="0" width="100%" height="64" background="<%=basePath%>/background/Images/top_top_bg.gif">  
  34.             <tr valign="top">  
  35.                 <td width="50%"><a href="javascript:void(0)"><img style="border:none" src="<%=basePath%>/background/Images/logo.png" /></a></td>  
  36.                 <td width="30%" style="padding-top:13px;font:15px Arial,SimSun,sans-serif;color:#FFF">尊敬的:<b style="color: red"><%=((UserBean)session.getAttribute("Logindo")).getUser_name()%></b> 您好,感谢登陆使用!</td>  
  37.                 <td style="padding-top:10px;" align="center"></td>  
  38.                 <td style="padding-top:10px;" align="center"><a href="javascript:void(0)"><img style="border:none" src="<%=basePath%>/background/Images/out.gif" onclick="logout();" /></td>  
  39.             </tr>  
  40.         </table>  
  41.     </body>  
  42.     <script type="text/javascript">  
  43.       
  44.           
  45.     </script>  
  46. </html>  

left.jsp

[html]  view plain  copy
  1. <%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'left.jsp' starting page</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <!-- 
  20.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  21.     -->  
  22.     <script src="<%=basePath%>/background/Js/prototype.lite.js" type="text/javascript"></script>  
  23.     <script src="<%=basePath%>/background/Js/moo.fx.js" type="text/javascript"></script>  
  24.     <script src="<%=basePath%>/background/Js/moo.fx.pack.js" type="text/javascript"></script>  
  25.     <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />  
  26.     <script type="text/javascript">  
  27.         window.onload = function () {  
  28.             var contents = document.getElementsByClassName('content');  
  29.             var toggles = document.getElementsByClassName('type');  
  30.   
  31.             var myAccordion = new fx.Accordion(  
  32.             toggles, contents, {opacity: true, duration: 400}  
  33.             );  
  34.             myAccordion.showThisHideOpen(contents[0]);  
  35.             for(var i=0; i<document .getElementsByTagName("a").length; i++){  
  36.                 var dl_a = document.getElementsByTagName("a")[i];  
  37.                     dl_a.onfocus=function(){  
  38.                         this.blur();  
  39.                     }  
  40.             }  
  41.         }  
  42.     </script>  
  43.   </head>  
  44.     
  45.   <body>  
  46.     <table width="100%" height="280" border="0" cellpadding="0" cellspacing="0" bgcolor="#EEF2FB">  
  47.         <tr>  
  48.             <td width="182" valign="top">  
  49.             <!-- 根据数据库的权限表获取到的权限来展开导航栏 -->  
  50.             <%List<FuncBean> funcBeans =(List<FuncBean>)session.getAttribute("funcs");  
  51.          
  52.              %>  
  53.                
  54.                 <div id="<a href="http://lib.csdn.net/base/4" class="replace_word" title="Docker知识库" target="_blank" style="color:#df3434; font-weight:bold;">container</a>">  
  55.                 <!-- 权限等级为1的为1级导航栏 -->  
  56.                 <%for(int i=0;i<funcBeans.size();i++){   
  57.                     if(funcBeans.get(i).getFunc_level().equals("1")){  
  58.                       
  59.                 %>  
  60.                     <h1 class="type"><a href="javascript:void(0)"><%=funcBeans.get(i).getFunc_name() %></a></h1>  
  61.                     <div class="content">  
  62.                         <table width="100%" border="0" cellspacing="0" cellpadding="0">  
  63.                             <tr>  
  64.                                 <td><img src="<%=basePath%>/background/Images/menu-top-line.gif" width="182" height="5" /></td>  
  65.                             </tr>  
  66.                         </table>  
  67.                         <ul class="RM">  
  68.                         <!-- 权限等级为2的为2级导航栏 -->  
  69.                         <%for(int j=0;j<funcBeans.size();j++){   
  70.                             FuncBean funcBean =funcBeans.get(j);  
  71.                             if(funcBean.getFunc_level().equals("2")&&funcBean.getFunc_pid()==funcBeans.get(i).getFunc_id()){  
  72.                         %>  
  73.                             <li><a href="<%=funcBeans.get(j).getFunc_url()%>" target="main"><%=funcBeans.get(j).getFunc_name() %></a></li>  
  74.                             <%}} %>  
  75.                         </ul>  
  76.                     </div>       
  77.                        <% }}%>     
  78.                 </div>  
  79.                  
  80.             </td>  
  81.         </tr>  
  82.     </table>  
  83. </body>  
  84. </html>  

main.jsp

[html]  view plain  copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'main.jsp' starting page</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <!-- 
  20.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  21.     -->  
  22.     <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />  
  23.   </head>  
  24.     
  25.   <body>  
  26.         <table width="100%" border="0" cellpadding="0" cellspacing="0">  
  27.             <!-- 头部开始 -->  
  28.             <tr>  
  29.                 <td width="17" valign="top" background="<%=basePath%>/background/Images/mail_left_bg.gif">  
  30.                     <img src="<%=basePath%>/background/Images/left_top_right.gif" width="17" height="29" />  
  31.                 </td>  
  32.                 <td valign="top" background="<%=basePath%>/background/Images/content_bg.gif">  
  33.                     <table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" background="<%=basePath%>/background/<%=basePath%>/background/Images/content_bg.gif">  
  34.                         <tr><td height="31"><div class="title" style="color: red">欢迎界面</div></td></tr>  
  35.                     </table>  
  36.                 </td>  
  37.                 <td width="16" valign="top" background="<%=basePath%>/background/Images/mail_right_bg.gif"><img src="<%=basePath%>/background/Images/nav_right_bg.gif" width="16" height="29" /></td>  
  38.             </tr>  
  39.             <!-- 中间部分开始 -->  
  40.             <tr>  
  41.                 <!--第一行左边框-->  
  42.                 <td valign="middle" background="<%=basePath%>/background/Images/mail_left_bg.gif"> </td>  
  43.                 <!--第一行中间内容-->  
  44.                 <td valign="top" bgcolor="#F7F8F9">  
  45.                     <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">  
  46.                         <!-- 空白行-->  
  47.                         <tr><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>  
  48.                         <!--**********这里是内容**********-->  
  49.                         <!--**********这里是内容**********-->  
  50.                         <!--**********这里是内容**********-->  
  51.                         <!--**********这里是内容**********-->  
  52.                         <tr>  
  53.                             <!--左边内容-->  
  54.                             <td colspan="2" valign="top">  
  55.                                 <h3 style="margin:0 0 10px 10px; color: blue">感谢您使用传一科技驾校管理程序</h3>  
  56.                                 <img src="<%=basePath%>/background/Images/ts.gif" width="16" height="16" style="margin-left:10px;"> 提示:<br />  
  57.                                 <p style="text-indent:20px;line-height:25px;margin-left:10px;font-size:15px;">您现在使用的是 传一科技开发的一套驾校管理系统!如果您有任何疑问请联系客户服务邮箱进行咨询!<br />    此程序是为您便捷管理驾校而使用!</p>  
  58.                             </td>  
  59.                             <!--间隔-->  
  60.                             <td width="7%"> </td>  
  61.                             <!--右边内容-->  
  62.                             <td width="40%" valign="top">  
  63.                                 <table width="100%" height="150" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #CCCCCC;">  
  64.                                     <tr>  
  65.                                         <td width="7%" height="27" background="<%=basePath%>/background/Images/news_title_bg.gif">  
  66.                                             <img src="<%=basePath%>/background/Images/news_title_bg.gif" width="2" height="27">  
  67.                                         </td>  
  68.                                         <td width="93%" background="<%=basePath%>/background/Images/news_title_bg.gif" class="left_bt">最新动态</td>  
  69.                                     </tr>  
  70.                                     <tr><td height="5" colspan="2"> </td></tr>  
  71.                                     <tr>  
  72.                                         <td height="100" valign="top" colspan="2" id="news">  
  73.                                             <marquee direction="up" scrollamount="2" vspace="30px" width="400px" height="100px" onmouseout="this.start()" onmouseover="this.stop()">  
  74.                                                 <ul>  
  75.                                                     <li>厦门传一科技有限公司!</li>  
  76.                                                     <li>传一科技驾校管理系统!</li>  
  77.                                                 </ul>  
  78.                                             </marquee>  
  79.                                         </td>  
  80.                                     </tr>  
  81.                                     <tr><td height="5" colspan="2"> </td></tr>  
  82.                                 </table>  
  83.                             </td>  
  84.                         </tr>  
  85.                         <tr height="20"><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>  
  86.                         <!--第二行-->  
  87.                         <tr>  
  88.                             <td colspan="2" valign="top">  
  89.                                 <table width="100%" height="230" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #CCCCCC;">  
  90.                                     <tr>  
  91.                                         <td width="7%" background="<%=basePath%>/background/Images/news_title_bg.gif">  
  92.                                             <img src="<%=basePath%>/background/Images/news_title_bg.gif" width="2" height="27">  
  93.                                         </td>  
  94.                                         <td width="93%" background="<%=basePath%>/background/Images/news_title_bg.gif" class="left_bt">最新动态</td>  
  95.                                     </tr>  
  96.                                     <tr>  
  97.                                         <td height="186" valign="top" colspan="2"></td>  
  98.                                     </tr>  
  99.                                     <tr><td height="5" colspan="2"> </td></tr>  
  100.                                 </table>  
  101.                             </td>  
  102.                             <td> </td>  
  103.                             <td valign="top">  
  104.                                 <table width="100%" height="230" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #CCCCCC;">  
  105.                                     <tr>  
  106.                                         <td width="7%" background="<%=basePath%>/background/Images/news_title_bg.gif">  
  107.                                             <img src="<%=basePath%>/background/Images/news_title_bg.gif" width="2" height="27">  
  108.                                         </td>  
  109.                                         <td width="93%" height="27" background="<%=basePath%>/background/Images/news_title_bg.gif" class="left_bt">最新动态</td>  
  110.                                     </tr>  
  111.                                     <tr><td height="186" valign="top"> </td><td height="102" valign="top"></td></tr>  
  112.                                     <tr><td height="5" colspan="2"> </td></tr>  
  113.                                 </table>  
  114.                             </td>  
  115.                         </tr>  
  116.                         <tr>  
  117.                             <td height="40" colspan="4">  
  118.                                 <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">  
  119.                                     <tr><td></td></tr>  
  120.                                 </table>  
  121.                             </td>  
  122.                         </tr>  
  123.                         <tr>  
  124.                             <td width="2%"> </td>  
  125.                             <td width="51%" class="left_txt">  
  126.                                 <img src="<%=basePath%>/background/Images/icon_mail.gif" width="16" height="11"> 客户服务邮箱:870873201@qq.com<br />  
  127.                                 <img src="<%=basePath%>/background/Images/icon_phone.gif" width="17" height="14"> 官方网站:<a href="http://my.csdn.net/xie_xiansheng" target="_blank">作者博客</a>  
  128.                             </td>  
  129.                             <td> </td><td> </td>  
  130.                         </tr>  
  131.                     </table>  
  132.                 </td>  
  133.                 <td background="<%=basePath%>/background/Images/mail_right_bg.gif"> </td>  
  134.             </tr>  
  135.             <!-- 底部部分 -->  
  136.             <tr>  
  137.                 <td valign="bottom" background="<%=basePath%>/background/Images/mail_left_bg.gif">  
  138.                     <img src="<%=basePath%>/background/Images/buttom_left.gif" width="17" height="17" />  
  139.                 </td>  
  140.                 <td background="<%=basePath%>/background/Images/buttom_bgs.gif">  
  141.                     <img src="<%=basePath%>/background/Images/buttom_bgs.gif" width="17" height="17">  
  142.                 </td>  
  143.                 <td valign="bottom" background="<%=basePath%>/background/Images/mail_right_bg.gif">  
  144.                     <img src="<%=basePath%>/background/Images/buttom_right.gif" width="16" height="17" />  
  145.                 </td>             
  146.             </tr>  
  147.         </table>  
  148.     </body>  
  149. </html>  

最后是过滤器类:org.great.filter下的LoginFilter

[java]  view plain  copy
  1. public class LoginFilter implements Filter{  
  2.   
  3.     public void doFilter(ServletRequest sreq, ServletResponse sresp,  
  4.             FilterChain chain) throws IOException, ServletException {  
  5.         HttpServletRequest req = (HttpServletRequest)sreq;  
  6.         HttpServletResponse resp = (HttpServletResponse) sresp;  
  7.           
  8.         HttpSession session = req.getSession();  
  9.         String path = req.getServletPath();  
  10.         String apath = req.getContextPath();  
  11.         //如果是路径以/index.jsp  /background(图片存放文件) /login.do 开始的直接放过,其他的拦截判断  
  12.         if(!path.startsWith("/index.jsp")&&!path.startsWith("/background")&&!path.startsWith("/login.do")){  
  13.             Object object = session.getAttribute("Logindo");  
  14.             if(object ==null){  
  15.                 resp.sendRedirect(apath+"/index.jsp");  
  16.             }else{  
  17.                 chain.doFilter(req, resp);  
  18.             }  
  19.         }else{  
  20.             chain.doFilter(req, resp);  
  21.         }  
  22.           
  23.     }  
  24.   
  25.     public void init(FilterConfig arg0) throws ServletException {  
  26.           
  27.     }  
  28.       
  29.     public void destroy() {  
  30.           
  31.     }  
  32.   
  33. }  

并且在web.xml进行配置:

[html]  view plain  copy
  1. <servlet>  
  2.     <servlet-name>loginServlet</servlet-name>  
  3.     <servlet-class>org.great.servlet.LoginServlet</servlet-class>  
  4.   </servlet>  
  5.   <servlet-mapping>  
  6.     <servlet-name>loginServlet</servlet-name>  
  7.     <url-pattern>/login.do</url-pattern>  
  8.   </servlet-mapping>  
  9.     
  10.    <filter>  
  11.     <filter-name>loginFilter</filter-name>  
  12.     <filter-class>org.great.filter.LoginFilter</filter-class>  
  13.   </filter>  
  14.   <filter-mapping>  
  15.     <filter-name>loginFilter</filter-name>  
  16.     <url-pattern>/*</url-pattern>  
  17.   </filter-mapping>  
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该项目是用JAVA-Swing编写。需要建立一个mysql表。因为软件问题无法导出,请读者自行创建。表的列数据在下载文件的截图中,因为程序有导出数据库到Excel文件和界面美化(共27个皮肤),所以需要导入两个jar包,在下载文件里,复制这两个文件在exlipse中点击课程设计然后粘贴,再右击这两个包点击build path->第一个,这就是这两个包的导入方法。皮肤无法动态更换,在主界面中代码可以找到。下面是整个课程设计的需求。 天津市瑞聪驾驶员学校为简化人工劳动,提高管理效率,帮助管理者便捷科学管理培训信息,决定开发一套驾校管理系统,实现以下需求。 1)软件的使用者是驾校负责人,负责人可以通过软件录入驾校学员信息(包括姓名、性别、电话、身份证号码、照片、报名时间、学费金额、考试进度)。 2)负责人可以通过软件录入驾校教练信息(包括姓名、电话、照片等)、驾校车辆信息(车牌号、车型、车龄)。 3)负责人可以在软件中浏览学员、教练和车辆的信息概况(JTable或JList),可以查看选中记录的详细信息;可以编辑更新记录信息。 4)负责人可以通过软件为一个或一批学员新建学车记录,即为学员安排教练、车辆、练车日期和练车时长等信息。 5)软件可以根据练车记录,统计指定时间段内学员的练车总时间、教练教学总时间、驾校报名总收入等不同信息。 6)负责人可以将学员练车记录导出到txt文件或excel文件 7)除以上功能外,还可根据实际需要添加其他功能。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值