Reputation: 39
This is the first time for me to work with Struts1. I want to redirect from a jsp to another jsp. For example: if the user not in session then redirect it to login.jsp; else go to menu.jsp.
I tried to make a tile: isLogged.jsp that contains:
<logic:present name="user">
<jsp:forward page="menu.do"/>
</logic:present>
<logic:notPresent name="user">
<jsp:forward page="login.do"/>
</logic:notPresent>
But it don´t redirect and the page is in blank (all empty in the code).
I do call the tile in all the pages of the site inside of the .
What am I doing wrong?
Upvotes: 1
Views: 5852
Reputation: 42010
There are several solutions 1:
If you have in your struts-config.xml
:
<action-mappings>
<action path="/login" forward="/login.jsp"/>
<action path="/menu" forward="/menu.jsp"/>
</action-mappings>
You can try (as in your code):
<logic:present name="user">
<jsp:forward page="menu.do" />
</logic:present>
<logic:notPresent name="user">
<jsp:forward page="login.do" />
</logic:notPresent>
<logic:present name="user">
<jsp:forward page="/menu.jsp" />
</logic:present>
<logic:notPresent name="user">
<jsp:forward page="/login.jsp" />
</logic:notPresent>
logic:redirect
<logic:present name="user">
<logic:redirect page="/menu.jsp" />
</logic:present>
<logic:notPresent name="user">
<logic:redirect page="/login.jsp" />
</logic:notPresent>
global-forwards
If you have in your struts-config.xml
:
<global-forwards>
<forward name="login" path="/login.jsp"/>
<forward name="menu" path="/menu.jsp"/>
</global-forwards>
You can try:
<logic:present name="user">
<logic:forward name="menu" />
</logic:present>
<logic:notPresent name="user">
<logic:forward name="login" />
</logic:notPresent>
Notes
WebContent
folder if you are using an standar eclipse project). If you have your files in another path, for example, in the WEB-INF
folder, you should just change it to that.Upvotes: 4