我写了一个struts拦截器,验证没有登录的时候跳转到登录页面,但是页面使用iframe内嵌,跳转的时候只有内嵌的页面跳转到登录页面,登录之后整天页面出现在内嵌的页面,这样很不合理,有没有什么好办法解决这个问题,struts拦截器验证没有登录的时候让整个界面跳转到login.jsp页面怎么设置
<global-results>
<result name="noPatient" type="redirect">/page/index/index.jsp</result>
</global-results>Strutsredirect
<global-results>
<result name="noPatient" type="redirect">/page/index/index.jsp</result>
</global-results>Strutsredirect
解决方案 »
- spring3 applicationContext.xml 如何配置多个DAO?
- 总是出现java.lang.NullPointerException
- ejb如何部署,连接数据库
- jdk1.2 怎么调用 webservice
- springmodules使用ehcache报错!求救!
- 关于EJB与其他框架的区别
- JBoss 下的 log4j 问题
- j2ee sdk 安装问题
- 为什么在tomcat中,HTML页面中JPG的图片和SWF(flash)不能显示?而GIF的图可以显示?
- java把一组从Oracle提出出来的数据放入到数组中并单独使用每一个数据
- 请问一个问题,struts2 json 和aop cglib在异步时问题,谢谢
- 内存问题,请教大师如何优化
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* 拦截学生未登录就去访问一些action
* @author Administrator
*
*/
public class StudentLoginInterceptor extends AbstractInterceptor { @Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
Map<String, Object> session = ctx.getSession();
Student student = (Student) (session.get("STUDENT_LOGIN"));
if (student != null)
return invocation.invoke();
return Action.LOGIN;
}
}最后如果没有登录就让action返回一个"LOGIN"再在struts.xml中加上
<result name="LOGIN" type="redirect">/page/index/index.jsp</result>
</global-results>
加外还要在struts.xml中加上
<interceptors>
<interceptor name="studentLoginInterceptor"
class="beyond.library.interceptor.StudentLoginInterceptor">
</interceptor>
</interceptors>
你想拦截哪个action,就在哪个action的下面加上
<interceptor-ref name="studentLoginInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
其中第二个defaultStack是struts本来有的,一定要加上。
就这么配置就行了