最近编码过程中,遇到这样一个问题,没有好好研究,不知道怎么解决,记录下拉,希望自己不要忘记。
问题的起因:用户登陆后,建立session,未登陆,就通过拦截器,检查访问action,是否执行。这个需求和struts2的拦截器教程差不多。
问题描述: 由于我前台只需要json,很多action 都不需要跳转,也就是说,返回值是 null;
范例代码如下:
配置:
这种action ,如果,我在不建立session的情况下访问, 拦截器是执行了,但是没有办法执行跳转功能。
没有细细研究,只是试了下, 如果action 有返回值, return SUCCESS;
这样的action就可以通过拦截器跳转到,配置的全局 result 。
记录在此。。
问题的起因:用户登陆后,建立session,未登陆,就通过拦截器,检查访问action,是否执行。这个需求和struts2的拦截器教程差不多。
问题描述: 由于我前台只需要json,很多action 都不需要跳转,也就是说,返回值是 null;
范例代码如下:
public String getTree() throws Exception{
String id = this.servletRequest.getParameter("node").trim();
if(!id.equals("-2")){
id=id.substring(1, id.length());
}
SysUser user=(SysUser) this.session.get("user");
String net_id=sysCommService.getUserNet(user);
String json=areaNewService.getForTree(StringUtils.parseLong(id),net_id);
this.responseWrite(json);
logger.debug(json);
return null;//最关键的部分。
}
配置:
<action name="getTree"
class="xxxAction" method="getDeviceTree">
</action>
这种action ,如果,我在不建立session的情况下访问, 拦截器是执行了,但是没有办法执行跳转功能。
没有细细研究,只是试了下, 如果action 有返回值, return SUCCESS;
这样的action就可以通过拦截器跳转到,配置的全局 result 。
记录在此。。