本节博文将向大家介绍本次驾培管理系统的登录功能。从创建一个对应数据表的bean开始,到界面填入参数,后台判断,传值,并且实现页面渲染,通过登录这一基础功能向大家展示这一流程,以供像我一样的初学者们学习。
首先来看结果图
首先是数据库所创建的用户表格t_user:
然后是数据库所有权限的表格t_function:
最后是数据库对应用户所拥有权限的表格t_user_function:
其次,是org.great.bean包下用户表t_user对应的UserBean
- package org.great.bean;
- public class UserBean {
- private int user_id;
- private int role_id;
- private int driving_id;
- private String user_lname;
- private String user_pwd;
- private String user_name;
- private String user_sex;
- private String user_status;
- private String createtime;
- private String tel;
- private String driving_name;
- public String getDriving_name() {
- return driving_name;
- }
- public void setDriving_name(String drivingName) {
- driving_name = drivingName;
- }
- public int getUser_id() {
- return user_id;
- }
- public void setUser_id(int userId) {
- user_id = userId;
- }
- public int getRole_id() {
- return role_id;
- }
- public void setRole_id(int roleId) {
- role_id = roleId;
- }
- public String getUser_lname() {
- return user_lname;
- }
- public void setUser_lname(String userLname) {
- user_lname = userLname;
- }
- public String getUser_pwd() {
- return user_pwd;
- }
- public void setUser_pwd(String userPwd) {
- user_pwd = userPwd;
- }
- public String getUser_name() {
- return user_name;
- }
- public void setUser_name(String userName) {
- user_name = userName;
- }
- public String getUser_sex() {
- return user_sex;
- }
- public void setUser_sex(String userSex) {
- user_sex = userSex;
- }
- public String getUser_status() {
- return user_status;
- }
- public void setUser_status(String userStatus) {
- user_status = userStatus;
- }
- public String getCreatetime() {
- return createtime;
- }
- public void setCreatetime(String createtime) {
- this.createtime = createtime;
- }
- public int getDriving_id() {
- return driving_id;
- }
- public void setDriving_id(int drivingId) {
- driving_id = drivingId;
- }
- public String getTel() {
- return tel;
- }
- public void setTel(String tel) {
- this.tel = tel;
- }
- }
权限表t_function对应的FuncBean:
- package org.great.bean;
- public class FuncBean {
- private int func_id;
- private int func_pid;
- private String func_name;
- private String func_url;
- private String func_level;
- private String func_tag;
- public int getFunc_id() {
- return func_id;
- }
- public void setFunc_id(int funcId) {
- func_id = funcId;
- }
- public int getFunc_pid() {
- return func_pid;
- }
- public void setFunc_pid(int funcPid) {
- func_pid = funcPid;
- }
- public String getFunc_name() {
- return func_name;
- }
- public void setFunc_name(String funcName) {
- func_name = funcName;
- }
- public String getFunc_url() {
- return func_url;
- }
- public void setFunc_url(String funcUrl) {
- func_url = funcUrl;
- }
- public String getFunc_level() {
- return func_level;
- }
- public void setFunc_level(String funcLevel) {
- func_level = funcLevel;
- }
- public String getFunc_tag() {
- return func_tag;
- }
- public void setFunc_tag(String funcTag) {
- func_tag = funcTag;
- }
- }
然后是org.great.dao包下创建UserDao类,并且创建一个工厂类,控制单例,使之每次只实例化一个Dao
UserDao类:
- public interface UserDao {
- /**根据登录名查找用户信息*/
- public UserBean findUser_ByLname(String lname);
- }
DaoFactory类:
- public class DaoFactory {
- private static UserDao userDao = null;
- private static FuncDao funcDao = null;
- <span style="white-space:pre"> </span>public static FuncDao getFuncDao(){
- <span style="white-space:pre"> </span>if(funcDao == null){
- <span style="white-space:pre"> </span>funcDao = new FuncDaoImpl();
- <span style="white-space:pre"> </span>}
- <span style="white-space:pre"> </span>return funcDao;
- <span style="white-space:pre"> </span>}
- public static UserDao getUserDao(){
- if(userDao == null){
- userDao = new UserDaoImpl();
- }
- return userDao;
- }
- }
FuncDaoImpl实现类对应进行数据库查询操作:
- private PreparedStatement pre = null;
- private ResultSet rs = null;
- /** 获得权限表全部数据*/
- public List<FuncBean> getFunc_ALL(int user_id){
- List<FuncBean> list = new ArrayList<FuncBean>();
- Connection conn = DBUtils.getConn();
- String sql = "select f.func_id,f.func_pid,f.func_name,f.func_url,f.func_level from t_function f," +
- "t_user_function rf where f.func_id = rf.func_id and rf.user_id = ?";
- try {
- pre = conn.prepareStatement(sql);
- pre.setInt(1, user_id);
- rs = pre.executeQuery();
- while(rs.next()){
- FuncBean funcBean = new FuncBean();
- funcBean.setFunc_id(rs.getInt(1));
- funcBean.setFunc_pid(rs.getInt(2));
- funcBean.setFunc_name(rs.getString(3));
- funcBean.setFunc_url(rs.getString(4));
- funcBean.setFunc_level(rs.getString(5));
- list.add(funcBean);
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally{
- DBUtils.close(conn, pre, rs);
- }
- return list;
- }
UserDaoImpl实现类对应的数据库查询操作:
- private PreparedStatement pre = null;
- private ResultSet rs = null;
- public UserBean findUser_ByLname(String lname) {
- Connection conn = DBUtils.getConn();
- UserBean userBean = null;
- String sql = "select user_id,role_id,user_lname,user_pwd,user_name,user_sex,user_status," +
- "createtime,driving_id,tel from t_user where user_lname = ? and user_status!='D'" ;
- try {
- pre = conn.prepareStatement(sql);
- pre.setString(1, lname);
- rs = pre.executeQuery();
- if(rs.next()){
- userBean = new UserBean();
- userBean.setUser_id(rs.getInt(1));
- userBean.setRole_id(rs.getInt(2));
- userBean.setUser_lname(rs.getString(3));
- userBean.setUser_pwd(rs.getString(4));
- userBean.setUser_name(rs.getString(5));
- userBean.setUser_sex(rs.getString(6));
- userBean.setUser_status(rs.getString(7));
- userBean.setCreatetime(rs.getString(8));
- userBean.setDriving_id(rs.getInt(9));
- userBean.setTel(rs.getString(10));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally{
- DBUtils.close(conn, pre, rs);
- }
- return userBean;
- }
org.great.servlet包下的登录判断的Servlet类:LoginServlet
- public class LoginServlet extends HttpServlet{
- @Override
- protected void service(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- req.setCharacterEncoding("utf-8");
- resp.setContentType("text/html;charset=utf-8");
- String task = req.getParameter("task");
- if(null == task){
- req.setAttribute("msg", "请先登录!");
- req.getRequestDispatcher("index.jsp").forward(req, resp);
- }else if(task.equals("login")){
- String userlname = req.getParameter("userlname");
- String userpwd = req.getParameter("userpwd");
- if("".equals(userlname)|| "".equals(userpwd)){
- req.setAttribute("msg","用户名或密码不能为空!");
- req.getRequestDispatcher("index.jsp").forward(req, resp);
- }else {
- System.out.println("task--111"+task);
- UserDao userDao = DaoFactory.getUserDao();
- //通过登录账户名获取用户信息
- UserBean userBean = userDao.findUser_ByLname(userlname);
- if(null==userBean){
- req.setAttribute("msg", "用户名不存在");
- req.getRequestDispatcher("index.jsp").forward(req, resp);
- }else if(!userpwd.equals(userBean.getUser_pwd())){
- req.setAttribute("msg", "密码输入错误");
- req.getRequestDispatcher("index.jsp").forward(req, resp);
- }else if(userBean.getRole_id()==3||userBean.getRole_id()==4){
- req.setAttribute("msg", "抱歉,您没有权限登录");
- req.getRequestDispatcher("index.jsp").forward(req, resp);
- }else{
- //列出权限->左侧导航栏
- HttpSession session = req.getSession();
- FuncDao funcDao = DaoFactory.getFuncDao();
- List<FuncBean> funcBeans = funcDao.getFunc_ALL(userBean.getUser_id());
- session.setAttribute("funcs", funcBeans);
- session.setAttribute("Logindo", userBean);
- session.setAttribute("funcDao", funcDao);
- resp.sendRedirect("jsp/main/index.jsp");
- }
- }
- }
- }
- }
WebRoot/index.jsp,项目初始页面(登录页面)
- <%@ 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"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
- <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>
- <script type="text/javascript" src="<%=basePath%>/easyvalidator2/js/validate.pack.js">
- </script>
- <link href="<%=basePath%>/easyvalidator2/css/validate.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <table width="100%">
- <!-- 顶部部分 -->
- <tr height="41"><td colspan="2" background="<%=basePath%>/background/Images/login_top_bg.gif"> </td></tr>
- <!-- 主体部分 -->
- <tr style="background:url(<%=basePath%>/background/Images/login_bg.jpg) repeat-x;" height="532">
- <!-- 主体左部分 -->
- <td id="left_cont">
- <table width="100%" height="100%">
- <tr height="155"><td colspan="2"> </td></tr>
- <tr>
- <td width="20%" rowspan="2"> </td>
- <td width="60%">
- <table width="100%">
- <tr height="70"><td align="right"></td></tr>
- <tr height="274">
- <td valign="top" align="right">
- </td>
- </tr>
- </table>
- <td width="15%" rowspan="2"> </td>
- </td>
- </tr>
- <tr><td colspan="2"> </td></tr>
- </table>
- </td>
- <!-- 主体右部分 -->
- <td id="right_cont">
- <table height="100%">
- <tr height="30%"><td colspan="3"> </td></tr>
- <tr>
- <td width="30%" rowspan="5"> </td>
- <td valign="top" id="form">
- <form action="login.do" method="post">
- <table valign="top" width="50%">
- <tr><td colspan="2"><h4 style="letter-spacing:1px;font-size:16px;">驾校管理后台</h4></td></tr>
- <tr>
- <td>用户名:</td>
- <td>
- <input type="text" name="userlname" value="" />
- </td>
- </tr>
- <tr><td>密 码:</td><td><input type="password" name="userpwd" value="" />
- <input type="hidden" name="task" value="login">
- </td></tr>
- <tr class="bt" align="center"><td> <input type="submit" value="登陆" /></td><td> <input type="reset" value="重填" /></td></tr>
- </table>
- </form>
- </td>
- <td rowspan="5"> </td>
- </tr>
- <tr><td colspan="3"> </td></tr>
- </table>
- </td>
- </tr>
- <!-- 底部部分 -->
- <tr id="login_bot"><td colspan="2"><p>Copyright © 2015-2016 ChuanYi AX1510工作室</p></td></tr>
- </table>
- </body>
- <script type="text/javascript">
- var msg = "<%=request.getAttribute("msg")%>";
- if(msg!="null"){
- alert(msg);
- }
- </script>
- </html>
登录成功后跳转的Jsp:WebRoot/jsp/main/index.jsp,它包含了三个jsp,使用了frame框架
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <frameset rows="64,*" frameborder="no" border="0" framespacing="0">
- <!--头部-->
- <frame src="<%=basePath%>/jsp/main/top.jsp" name="top" noresize="noresize" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" />
- <!--主体部分-->
- <frameset cols="185,*">
- <!--主体左部分-->
- <frame src="<%=basePath%>/jsp/main/left.jsp" name="left" noresize="noresize" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" />
- <!--主体右部分-->
- <frame src="<%=basePath%>/jsp/main/main.jsp" name="main" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" />
- </frameset>
- </html>
top.jsp
- <%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'top.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
- <script type="text/javascript">
- function logout() {
- if(window.confirm('您确定要退出吗?')) {
- top.location = 'user.do?task=logout';
- }
- }
- </script>
- </head>
- <body>
- <table cellpadding="0" width="100%" height="64" background="<%=basePath%>/background/Images/top_top_bg.gif">
- <tr valign="top">
- <td width="50%"><a href="javascript:void(0)"><img style="border:none" src="<%=basePath%>/background/Images/logo.png" /></a></td>
- <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>
- <td style="padding-top:10px;" align="center"></td>
- <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>
- </tr>
- </table>
- </body>
- <script type="text/javascript">
- </script>
- </html>
left.jsp
- <%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'left.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- <script src="<%=basePath%>/background/Js/prototype.lite.js" type="text/javascript"></script>
- <script src="<%=basePath%>/background/Js/moo.fx.js" type="text/javascript"></script>
- <script src="<%=basePath%>/background/Js/moo.fx.pack.js" type="text/javascript"></script>
- <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
- <script type="text/javascript">
- window.onload = function () {
- var contents = document.getElementsByClassName('content');
- var toggles = document.getElementsByClassName('type');
- var myAccordion = new fx.Accordion(
- toggles, contents, {opacity: true, duration: 400}
- );
- myAccordion.showThisHideOpen(contents[0]);
- for(var i=0; i<document .getElementsByTagName("a").length; i++){
- var dl_a = document.getElementsByTagName("a")[i];
- dl_a.onfocus=function(){
- this.blur();
- }
- }
- }
- </script>
- </head>
- <body>
- <table width="100%" height="280" border="0" cellpadding="0" cellspacing="0" bgcolor="#EEF2FB">
- <tr>
- <td width="182" valign="top">
- <!-- 根据数据库的权限表获取到的权限来展开导航栏 -->
- <%List<FuncBean> funcBeans =(List<FuncBean>)session.getAttribute("funcs");
- %>
- <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>">
- <!-- 权限等级为1的为1级导航栏 -->
- <%for(int i=0;i<funcBeans.size();i++){
- if(funcBeans.get(i).getFunc_level().equals("1")){
- %>
- <h1 class="type"><a href="javascript:void(0)"><%=funcBeans.get(i).getFunc_name() %></a></h1>
- <div class="content">
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td><img src="<%=basePath%>/background/Images/menu-top-line.gif" width="182" height="5" /></td>
- </tr>
- </table>
- <ul class="RM">
- <!-- 权限等级为2的为2级导航栏 -->
- <%for(int j=0;j<funcBeans.size();j++){
- FuncBean funcBean =funcBeans.get(j);
- if(funcBean.getFunc_level().equals("2")&&funcBean.getFunc_pid()==funcBeans.get(i).getFunc_id()){
- %>
- <li><a href="<%=funcBeans.get(j).getFunc_url()%>" target="main"><%=funcBeans.get(j).getFunc_name() %></a></li>
- <%}} %>
- </ul>
- </div>
- <% }}%>
- </div>
- </td>
- </tr>
- </table>
- </body>
- </html>
main.jsp
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'main.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- <link rel="stylesheet" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
- </head>
- <body>
- <table width="100%" border="0" cellpadding="0" cellspacing="0">
- <!-- 头部开始 -->
- <tr>
- <td width="17" valign="top" background="<%=basePath%>/background/Images/mail_left_bg.gif">
- <img src="<%=basePath%>/background/Images/left_top_right.gif" width="17" height="29" />
- </td>
- <td valign="top" background="<%=basePath%>/background/Images/content_bg.gif">
- <table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" background="<%=basePath%>/background/<%=basePath%>/background/Images/content_bg.gif">
- <tr><td height="31"><div class="title" style="color: red">欢迎界面</div></td></tr>
- </table>
- </td>
- <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>
- </tr>
- <!-- 中间部分开始 -->
- <tr>
- <!--第一行左边框-->
- <td valign="middle" background="<%=basePath%>/background/Images/mail_left_bg.gif"> </td>
- <!--第一行中间内容-->
- <td valign="top" bgcolor="#F7F8F9">
- <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
- <!-- 空白行-->
- <tr><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>
- <!--**********这里是内容**********-->
- <!--**********这里是内容**********-->
- <!--**********这里是内容**********-->
- <!--**********这里是内容**********-->
- <tr>
- <!--左边内容-->
- <td colspan="2" valign="top">
- <h3 style="margin:0 0 10px 10px; color: blue">感谢您使用传一科技驾校管理程序</h3>
- <img src="<%=basePath%>/background/Images/ts.gif" width="16" height="16" style="margin-left:10px;"> 提示:<br />
- <p style="text-indent:20px;line-height:25px;margin-left:10px;font-size:15px;">您现在使用的是 传一科技开发的一套驾校管理系统!如果您有任何疑问请联系客户服务邮箱进行咨询!<br /> 此程序是为您便捷管理驾校而使用!</p>
- </td>
- <!--间隔-->
- <td width="7%"> </td>
- <!--右边内容-->
- <td width="40%" valign="top">
- <table width="100%" height="150" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #CCCCCC;">
- <tr>
- <td width="7%" height="27" background="<%=basePath%>/background/Images/news_title_bg.gif">
- <img src="<%=basePath%>/background/Images/news_title_bg.gif" width="2" height="27">
- </td>
- <td width="93%" background="<%=basePath%>/background/Images/news_title_bg.gif" class="left_bt">最新动态</td>
- </tr>
- <tr><td height="5" colspan="2"> </td></tr>
- <tr>
- <td height="100" valign="top" colspan="2" id="news">
- <marquee direction="up" scrollamount="2" vspace="30px" width="400px" height="100px" onmouseout="this.start()" onmouseover="this.stop()">
- <ul>
- <li>厦门传一科技有限公司!</li>
- <li>传一科技驾校管理系统!</li>
- </ul>
- </marquee>
- </td>
- </tr>
- <tr><td height="5" colspan="2"> </td></tr>
- </table>
- </td>
- </tr>
- <tr height="20"><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>
- <!--第二行-->
- <tr>
- <td colspan="2" valign="top">
- <table width="100%" height="230" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #CCCCCC;">
- <tr>
- <td width="7%" background="<%=basePath%>/background/Images/news_title_bg.gif">
- <img src="<%=basePath%>/background/Images/news_title_bg.gif" width="2" height="27">
- </td>
- <td width="93%" background="<%=basePath%>/background/Images/news_title_bg.gif" class="left_bt">最新动态</td>
- </tr>
- <tr>
- <td height="186" valign="top" colspan="2"></td>
- </tr>
- <tr><td height="5" colspan="2"> </td></tr>
- </table>
- </td>
- <td> </td>
- <td valign="top">
- <table width="100%" height="230" border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #CCCCCC;">
- <tr>
- <td width="7%" background="<%=basePath%>/background/Images/news_title_bg.gif">
- <img src="<%=basePath%>/background/Images/news_title_bg.gif" width="2" height="27">
- </td>
- <td width="93%" height="27" background="<%=basePath%>/background/Images/news_title_bg.gif" class="left_bt">最新动态</td>
- </tr>
- <tr><td height="186" valign="top"> </td><td height="102" valign="top"></td></tr>
- <tr><td height="5" colspan="2"> </td></tr>
- </table>
- </td>
- </tr>
- <tr>
- <td height="40" colspan="4">
- <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
- <tr><td></td></tr>
- </table>
- </td>
- </tr>
- <tr>
- <td width="2%"> </td>
- <td width="51%" class="left_txt">
- <img src="<%=basePath%>/background/Images/icon_mail.gif" width="16" height="11"> 客户服务邮箱:870873201@qq.com<br />
- <img src="<%=basePath%>/background/Images/icon_phone.gif" width="17" height="14"> 官方网站:<a href="http://my.csdn.net/xie_xiansheng" target="_blank">作者博客</a>
- </td>
- <td> </td><td> </td>
- </tr>
- </table>
- </td>
- <td background="<%=basePath%>/background/Images/mail_right_bg.gif"> </td>
- </tr>
- <!-- 底部部分 -->
- <tr>
- <td valign="bottom" background="<%=basePath%>/background/Images/mail_left_bg.gif">
- <img src="<%=basePath%>/background/Images/buttom_left.gif" width="17" height="17" />
- </td>
- <td background="<%=basePath%>/background/Images/buttom_bgs.gif">
- <img src="<%=basePath%>/background/Images/buttom_bgs.gif" width="17" height="17">
- </td>
- <td valign="bottom" background="<%=basePath%>/background/Images/mail_right_bg.gif">
- <img src="<%=basePath%>/background/Images/buttom_right.gif" width="16" height="17" />
- </td>
- </tr>
- </table>
- </body>
- </html>
最后是过滤器类:org.great.filter下的LoginFilter
- public class LoginFilter implements Filter{
- public void doFilter(ServletRequest sreq, ServletResponse sresp,
- FilterChain chain) throws IOException, ServletException {
- HttpServletRequest req = (HttpServletRequest)sreq;
- HttpServletResponse resp = (HttpServletResponse) sresp;
- HttpSession session = req.getSession();
- String path = req.getServletPath();
- String apath = req.getContextPath();
- //如果是路径以/index.jsp /background(图片存放文件) /login.do 开始的直接放过,其他的拦截判断
- if(!path.startsWith("/index.jsp")&&!path.startsWith("/background")&&!path.startsWith("/login.do")){
- Object object = session.getAttribute("Logindo");
- if(object ==null){
- resp.sendRedirect(apath+"/index.jsp");
- }else{
- chain.doFilter(req, resp);
- }
- }else{
- chain.doFilter(req, resp);
- }
- }
- public void init(FilterConfig arg0) throws ServletException {
- }
- public void destroy() {
- }
- }
并且在web.xml进行配置:
- <servlet>
- <servlet-name>loginServlet</servlet-name>
- <servlet-class>org.great.servlet.LoginServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>loginServlet</servlet-name>
- <url-pattern>/login.do</url-pattern>
- </servlet-mapping>
- <filter>
- <filter-name>loginFilter</filter-name>
- <filter-class>org.great.filter.LoginFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>loginFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>