补充:就是相当于再页面中加入
<%
if ((session == null) || session.getAttribute("userID") == null)
{
response.sendRedirect("../logon/login.jsp");
}%>的效果,但是我刚接触STRUTS,写不清楚标签的设置。谢谢尤其是怎么页面跳转
<%
if ((session == null) || session.getAttribute("userID") == null)
{
response.sendRedirect("../logon/login.jsp");
}%>的效果,但是我刚接触STRUTS,写不清楚标签的设置。谢谢尤其是怎么页面跳转
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
LoginForm loginForm = (LoginForm) form;
//这建立一个会话,用来保存登录后的信息
HttpSession session = request.getSession();
LoginCheck loginCheck=new LoginCheck();
if(loginCheck.isExist((LoginForm)form)){
//对这个会话设置属性,保存登录成功的用户名
session.setAttribute("user",loginForm.getUsername1());
return (mapping.findForward("success"));
}
else{
return (mapping.findForward("false"));
}
}}
你那个是再登陆的时候的验证?
我要的是在进入不用页面的时候对SESSION进行验证,验证失败跳转到登陆页面
用标签来实现
如果是这样的话,你去看孙卫琴那本书,有个例子就是这样的,好像是第二章吧
这样在每个页面开头只要加入标签就可以直接验证SESSION了,
手头上面没有资料啊。
现在也在上网找。
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
if(session==null || session.getAttribute(edu.sjtu.ebookstore.common.Constants.USER_KEY)==null) {
%>
<td width="60"><div align="center"><html:link href="login.jsp"><html:img width="24" height="21" border="0" src="image/logon.gif"/><BR>
<bean:message key="prompt.logon"/></html:link></div></td>
<% } else { %>
<td width="60"><div align="center"><html:link action="/logoffAction"><html:img width="24" height="21" border="0" src="image/logon.gif"/><BR>
<bean:message key="prompt.logoff"/></html:link></div></td>
<%} %>
</body>
</html:html>
假如上面的文件叫banner.jsp.
下面的就是应用它的标签例子,你可以把每个页都加上<tiles:insert page="/banner.jsp" flush="false" />这句。都能完成你的要求。
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html>
<head>
<title><bean:message key="title.index"/> </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<html:base/>
</head>
<tiles:insert page="/banner.jsp" flush="false" />
<body>
…………
…………
</body>
</html:html>