Struts2 高深问题 求高手解决

hechenqingtian 2010-01-26 08:15:04
public class AuthorityInterceptor extends AbstractInterceptor {

public AuthorityInterceptor() {
// TODO Auto-generated constructor stub
}

private Logger log = Logger.getLogger(AuthorityInterceptor.class);

@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
Map session = context.getSession();
TabUsers user =null;
if (session.get("managerEntity") != null) {
user = (TabUsers) session.get("managerEntity");
log.info("拦截器捕获.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + user.getNickname());
}
if (user == null) {
return new RedirectResult("/backmanager/first/edit.do").toString();
} else {
//return "/home/index";
return invocation.invoke();
}
}

}


上面的代码是Struts2 中的自定义拦截器,当我确定用户登录之后跳转到另一个action 的方法中
现在确定已经跳入到这个action的方法中,但是HttpServletRequest 对象获得为空。不知道这是
什么原因,希望高手能回答。

@Action("/backmanager/home/first/${type}/edit.do")
public String createframe() {
String realPath = getServletRequest().getRealPath("/");
contentService.setPath(realPath + "backmanager/content/content.xml");
log.info(" --" + contentService.getPath());
listContent = contentService.getList(type);
return "index";
}

上面的就是action 中跳转的方法
...全文
206 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
重返春季 2010-01-30
  • 打赏
  • 举报
回复
最好在网上搜索一下。或者看一下文档吧。顶一下!!
ralfbawg 2010-01-29
  • 打赏
  • 举报
回复
注解强大啊......学习ing....
redlotus_lyn 2010-01-28
  • 打赏
  • 举报
回复
1.拦截器:
public class AuthorityInterceptor extends AbstractInterceptor {

public AuthorityInterceptor() {
// TODO Auto-generated constructor stub
}

private Logger log = Logger.getLogger(AuthorityInterceptor.class);

@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext context = invocation.getInvocationContext();
Map session = context.getSession();
TabUsers user =null;
if (session.get("managerEntity") != null) {
user = (TabUsers) session.get("managerEntity");
}
if (user == null) {
return "actionResult";
} else {
//return "/home/index";
return invocation.invoke();
}
}
}

2.配置文件:
在你提交的Action加一个result。
<result name="actionResult" type="chain">
<param name="actionName">edit.do</param>
<param name="namespace">/backmanager/first</param>
</result>

注:chain结果类型能保存request。
wanli209 2010-01-28
  • 打赏
  • 举报
回复
getServletRequest()怎么写的
colin_pxx 2010-01-28
  • 打赏
  • 举报
回复
是不是你没有传HttpServletRequest对象啊
redlotus_lyn 2010-01-28
  • 打赏
  • 举报
回复
struts2是线程安全的。

return new RedirectResult("/backmanager/first/edit.do").toString();

redirect Action请求,struts2会创建一个新的ActionContext,原来的丢失。

luney3 2010-01-28
  • 打赏
  • 举报
回复
感觉应该要把HttpServletRequest 传递过去的吧??
道光2008 2010-01-28
  • 打赏
  • 举报
回复
注解编程惹得祸
nf0011468 2010-01-28
  • 打赏
  • 举报
回复
struts2的servletContext是这么取的ActionContext ac=ActionContext.getContext();
Purking 2010-01-28
  • 打赏
  • 举报
回复
你使用注解的形式仅仅配置了 Action 的映射路径,你将自定义的 Interceptor 加入到了这个 Action
需要经过的 Interceptor 链中去了吗??
xinlan1022 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zidasine 的回复:]
getServletRequest()这个方法怎么写的
[/Quote]

我也想知道这个方法怎么写的?
sunlaji008 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zl3450341 的回复:]
不太熟悉
楼主去看struts2的官方文档吧
[/Quote]
zl3450341 2010-01-26
  • 打赏
  • 举报
回复
不太熟悉
楼主去看struts2的官方文档吧
zidasine 2010-01-26
  • 打赏
  • 举报
回复
getServletRequest()这个方法怎么写的
crazylaa 2010-01-26
  • 打赏
  • 举报
回复
看看你的跳转是不是redirect="true"了,redirect之后原request过期,生成一个新的request,所以。。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧