struts2 package中继承了json-default,还可以跳页吗
发布网友
发布时间:2022-08-02 22:03
我来回答
共2个回答
热心网友
时间:2024-12-01 00:29
项目的页面全部由jquery、ajax实现,现在需要做一个权限*用以处理session过期及控制访问权限问题,但由于struts2的配置全部继承于json-default,在*中直接返回result的name属性时无论是redirect还是默认的dispatcher均不能控制页面跳转到目的页面,
如下操作
<!-- ajax 提示 * -->
<package name="authorityCheck" extends="json-default">
<interceptors>
<interceptor name="authority" class="com.incoshare.filter.PermissionInterceptor" />
</interceptors>
</package>
<!-- jsp跳转 * -->
<package name="authoritySruts" extends="struts-default">
<interceptors>
<interceptor name="authority" class="com.incoshare.filter.PermissionInterceptorJsp" />
</interceptors>
<global-results>
<result name="inter">/error/e_error.jsp</result>
<result name="uPermission">/WEB-INF/view/error/uPermission.jsp</result>
</global-results>
</package>
哪里需要就继承上边包,如
<struts>
<package name="jsp" extends="authoritySruts">
action name="DepartmentList" class="com.incoshare.action.usermanager.DepartmentAction"
method="to">
<result>/WEB-INF/view/userManager/department/list.jsp</result>
<result name="error">/error/e_error.jsp</result>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="authority">
<param name="funtionCode">u104</param>
</interceptor-ref>
</action>
。。。。
下边是*类:
public class PermissionInterceptorJsp extends AbstractInterceptor
{
private static final long serialVersionUID = 4573787592071643540L;
// 重写intercept方法
public String intercept(ActionInvocation _actionInvocation) throws Exception
{
ActionContext _actionContext = _actionInvocation.getInvocationContext();
HttpServletRequest _request = (HttpServletRequest) _actionContext
.get(StrutsStatics.HTTP_REQUEST);
/*
* HttpServletResponse _response = (HttpServletResponse) _actionContext
* .get(StrutsStatics.HTTP_RESPONSE);
*/
// 确认Session中是否存在UserSession
// Map<?, ?> _mapSession =
// _actionInvocation.getInvocationContext().getSession();
// UserSession _userSession = (UserSession)
// _mapSession.get("userSession");
UserSession _userSession = (UserSession) _request.getSession().getAttribute("userSession");
((ActionSupport) _actionInvocation.getAction()).clearMessages();
if (_userSession != null)
{
// 需要验证权限时
if (this.ifUserAccessUrl(_userSession))
{
// 有权限
//System.out.println("有权限--");
return _actionInvocation.invoke();
}
else
{
// 没有权限
//System.out.println("没有权限--");
((ActionSupport) _actionInvocation.getAction()).addActionMessage("您没有此权限");
return "uPermission";
}
}
else
{
// session 为NULL
//System.out.println("没有登陆--");
((ActionSupport) _actionInvocation.getAction()).addActionMessage("您还没有登录");
return "uPermission";
}
}
。。。。。。。。。。。。。。。。。。。
}
希望能帮助大家
热心网友
时间:2024-12-01 00:29
可以的,json-default它继承了struts-default