使用mainFrame登录问题。

两个工程,没做单点登录,a工程用b工程的页面,需要a工程登录才可以用

首先配置拦截器

<interceptors>
<interceptor name="sgAdminAuthorityInterceptor" class="org.scbit.lsbi.unilab.action.AdminAuthorityInterceptor"/>

</interceptors>

在需要加此拦截的action上加拦截

<action name="tjptSearchAccount" class="org.scbit.lsbi.unilab.action.TjptAction" method="adminSearchAccount">
<interceptor-ref name="noLoginInterceptor"></interceptor-ref>
<interceptor-ref name="sgAdminAuthorityInterceptor"/>
<result name="success" type="dispatcher">/WEB-INF/pages/lsc/tjpt/account_list.jsp</result>
</action>

org.scbit.lsbi.unilab.action.AdminAuthorityInterceptor对应代码

public class AdminAuthorityInterceptor extends AbstractInterceptor {

private static final long serialVersionUID = 1L;

public String intercept(ActionInvocation invocation) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String refer=request.getHeader("referer")!=null?request.getHeader("referer"):"";

List<String> ableRefer=new ArrayList<String>();
ableRefer.add("a工程的域名 如www.baidu.com");
Boolean checkRef = Boolean.FALSE;
String adminLogName=request.getParameter("userName");
for(int i=0;i<ableRefer.size() && !checkRef;i++){
String ableRef = ableRefer.get(i);
if(refer.startsWith(ableRef)&& StringUtils.isNotBlank(adminLogName)){
checkRef=Boolean.TRUE;
}
}


//已登录,继续用户操作
if( null != request.getSession().getAttribute("SESSION_TJPT_ADMIN")){
}else if (checkRef){
request.getSession().setAttribute("SESSION_TJPT_ADMIN",adminLogName);
}
else{
//进入登录页面
response.sendRedirect("a工程的登录地址");
return null;
}

return invocation.invoke();
}

}

原文地址:https://www.cnblogs.com/w1995w/p/10469714.html