本文主要讲述使用拦截器实现判断用户是否登录,在下边代码主要从页面向后台,后台从action--》service--》dao过程,最后展示配置的方式进行描述。
登录界面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/frameset.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css>
BODY {
FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: 宋体
}
TD {
FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: 宋体
}
</STYLE>
<META content="MSHTML 6.00.6000.16809" name=GENERATOR></HEAD>
<BODY>
<FORM id=form1 name=form1 action="${ pageContext.request.contextPath }/user_login.action" method=post target="_parent">
<DIV id=UpdatePanel1>
<DIV id=div1
style="LEFT: 0px; POSITION: absolute; TOP: 0px; BACKGROUND-COLOR: #0066ff"></DIV>
<DIV id=div2
style="LEFT: 0px; POSITION: absolute; TOP: 0px; BACKGROUND-COLOR: #0066ff"></DIV>
<DIV> </DIV>
<DIV>
<TABLE cellSpacing=0 cellPadding=0 width=900 align=center border=0>
<TBODY>
<TR>
<TD style="HEIGHT: 105px"><IMG src="images/login_1.gif"
border=0></TD></TR>
<TR>
<TD background=images/login_2.jpg height=300>
<TABLE height=300 cellPadding=0 width=900 border=0>
<TBODY>
<TR>
<TD colSpan=2 height=35></TD></TR>
<TR>
<TD width=360></TD>
<TD>
<s:actionerror/>
<TABLE cellSpacing=0 cellPadding=2 border=0>
<TBODY>
<TR>
<TD style="HEIGHT: 28px" width=80>登 录 名:</TD>
<TD style="HEIGHT: 28px" width=150><INPUT id=txtName
style="WIDTH: 130px" name="user_code"></TD>
<TD style="HEIGHT: 28px" width=370><SPAN
id=RequiredFieldValidator3
style="FONT-WEIGHT: bold; VISIBILITY: hidden; COLOR: white">请输入登录名</SPAN></TD></TR>
<TR>
<TD style="HEIGHT: 28px">登录密码:</TD>
<TD style="HEIGHT: 28px"><INPUT id=txtPwd style="WIDTH: 130px"
type=password name="user_password"></TD>
<TD style="HEIGHT: 28px"><SPAN id=RequiredFieldValidator4
style="FONT-WEIGHT: bold; VISIBILITY: hidden; COLOR: white">请输入密码</SPAN></TD></TR>
<TR>
<TD styl