如何将数据从Interceptor传递到URL和JSP?
我有一个身份验证拦截器来检查用户是否登录。 如果没有,它将重定向到登录页面,并使用查询字符串参数“url”指示引用网址。我尝试使用“actionInvocal.getInspirationContext().getParameters()”将值传递到重定向 URL,但没有运气。
谁能建议我做错了什么?多谢。
拦截器代码:
public String intercept(ActionInvocation actionInvocation) throws Exception {
Map session = actionInvocation.getInvocationContext().getSession();
Map params = actionInvocation.getInvocationContext().getParameters();
String user = (String) session.get(Constants.KEY_USER);
boolean isAuthenticated = (null!=user);
if (!isAuthenticated) {
params.put("backUrl", "http://www.some_url.com/");
return Action.LOGIN;
}
else {
return actionInvocation.invoke();
}
}
struts.xml部分
<global-results>
<result name="login" type="redirect">/login?url=${backUrl}</result>
I have an authen interceptor that check if user is logged in.
If not than it will redirect to the login page, with a query string param "url" indicating the referrer URL. I tried using "actionInvocation.getInvocationContext().getParameters()" for passing values to the redirect URL, but have no luck.
Can anyone suggest what I done wrong? Thanks a lot.
Interceptor code:
public String intercept(ActionInvocation actionInvocation) throws Exception {
Map session = actionInvocation.getInvocationContext().getSession();
Map params = actionInvocation.getInvocationContext().getParameters();
String user = (String) session.get(Constants.KEY_USER);
boolean isAuthenticated = (null!=user);
if (!isAuthenticated) {
params.put("backUrl", "http://www.some_url.com/");
return Action.LOGIN;
}
else {
return actionInvocation.invoke();
}
}
struts.xml parts
<global-results>
<result name="login" type="redirect">/login?url=${backUrl}</result>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查
struts.xml
文件中的拦截器顺序; params 拦截器应该放在登录拦截器之前:这是一个 示例
获取查询字符串的另一种方法是从属性
javax.servlet.forward.query_string
:Check the order of the interceptors in your
struts.xml
file; params interceptor should be placed before login interceptor:Here's an example
Another way to get the query string, is from the attribute
javax.servlet.forward.query_string
: