I have a slight problem with forwarding using Struts. Now when users accessing my page like this -> http://mypage/
they are automatically forwarded to /index.jsp.
But I'd also like to have index.jsp to be linked to name "sg".
So when they access page like this : http://mypage/
> they will be forwarded to http://mypage/sg
which is http://mypage/index.jsp
.
As I've already mentioned above I'm using Struts to handle all these action. The below example is what I have in my struts.xml file. But it's working rather partially. When I access the page as stated above I'm getting redirected to http://mypage/sg
and it also gives me 404 - Not Found .
However when I try manually accessing the url ( http://mypage/sg
), it works perfectly.
<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.
Answer :
If you want to call another action as result of one action then you need to mention attribute type
of result
tag
<action name="">
<result type="redirect">/sg</result>
</action>
This will redirect to action sg
.
The redirect result type calls the standard response.sendRedirect()
method, causing the browser to create a new request to the given location.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.