日期:2014-05-18  浏览次数:20650 次

求助,关于struts拦截器跳转的问题
我写了一个struts拦截器,验证没有登录的时候跳转到登录页面,但是页面使用iframe内嵌,跳转的时候只有内嵌的页面跳转到登录页面,登录之后整天页面出现在内嵌的页面,这样很不合理,有没有什么好办法解决这个问题,struts拦截器验证没有登录的时候让整个界面跳转到login.jsp页面怎么设置
<global-results>

<result name="noPatient" type="redirect">/page/index/index.jsp</result>
</global-results>
Struts redirect

------解决方案--------------------
如果是点击的话,,可以通过 <a target="_top"> 来实现 ,可惜不是

就目前看 后台配置没法 实现,,只能通过一个中间页面过度,,然后页面加载的时候触发类似<a target="_top"> 这样子的请求到你的登录页面、。。。
------解决方案--------------------
给你一个例子吧,下面是我做项目时写的
import com.opensymphony.xwork2.Action;
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本来有的,一定要加上。
就这么配置就行了。。。