【发布时间】:2014-02-06 08:53:48
【问题描述】:
我将 Struts 2 用于我的 Web 应用程序并使用身份验证部分。我想知道在重定向页面(操作)时,如何更改它重定向到的显示 URL 而不是来自?
比如我有一个login.action页面,会提交到authentication.action,如果用户名和密码正确,就会重定向到securePage.action。
我确实知道如何执行重定向部分(我尝试了链和 redirectAction 结果类型)。我想要的是当页面被重定向到安全页面时,URL 将显示 ..../securePage.action。现在,它仍然是带有会话 ID 的 authentication.action。
我在下面分享我的部分 struts.xml
<action name="login">
<result>index.jsp</result>
</action>
<action name="authentication" class="com.myapp.action.AuthenticationAction">
<result name="success" type="chain">hello</result>
<result name="failure">index.jsp</result>
</action>
<action name="hello"
class="com.myapp.action.HelloWorldAction"
method="execute">
<interceptor-ref name="myDefault"/>
<result name="success">/HelloWorld.jsp</result>
<result name="failure">index.jsp</result>
</action>
login.action 只会打开 index.jsp,这是将提交到身份验证的登录
身份验证的动作类简单地从登录中获取用户名和密码,如果通过则设置会话值“授权”,如果用户名和密码不匹配则重定向。
然后,身份验证将使用结果类型链重定向到 hello(安全页面)。
action for hello 使用我自己的 authInterceptor 来检查会话值——当前会话是否被授权。如果没有,请返回登录。
【问题讨论】:
-
在重定向操作的情况下,您是否指定了操作的结果(错误/成功)?您是否使用 URL 映射了这些操作?
-
你能分享你的 struts.xml 吗?我想看几件事
-
如果在 redirect 期间 URL 没有更改,那么您没有进行重定向。
-
我的观点正是@DaveNewton。
redirect将始终更新 URL。似乎 OP 配置了其他东西,使他对重定向感到困惑。也许像一个 ajax 调用或类似的东西 -
@Ved 是的。我做到了。我已经添加了我的 struts.xml 片段。