我在使用 Struts 转发时遇到了一个小问题。
现在,当用户像这样访问我的页面时 -> http://mypage/
它们会自动转发到/index.jsp。
但我还希望将index.jsp 链接到名称“sg”。
所以当他们访问这样的页面时:
http://mypage/
> 它们将被转发到 http://mypage/sg
这是http://mypage/index.jsp
。
正如我上面已经提到的,我使用 Struts 来处理所有这些操作。下面的示例是我的 struts.xml 文件中的内容。但它的工作相当部分。当我访问上述页面时,我会被重定向到 http://mypage/sg
,并且还会显示 404 - 未找到>。
但是,当我尝试手动访问网址(http://mypage/sg
)时,它工作得很好。
<package name="index" namespace="/" extends="default">
<action name="">
<result>/sg</result>
</action>
<action name="/sg">
<result>/index.jsp</result>
</action>
</package>
最佳答案
When I access the page as stated above I'm getting redirected to http://mypage.com/sg and it also gives me 404 - Not Found.
答案:
如果您想调用另一个操作作为一个操作的结果,那么您需要提及 result
标记的属性 type
<action name="">
<result type="redirect">/sg</result>
</action>
这将重定向到操作 sg
。
重定向结果类型:
重定向结果类型调用标准 response.sendRedirect()
方法,导致浏览器创建到给定位置的新请求。
关于java - 无法在Struts中设置转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22709357/