Reputation: 1521
Currently when you hit the root context of my application Struts2 throws an error:
returns
HTTP ERROR 404
Problem accessing /. Reason:
There is no Action mapped for namespace / and action name .
Is there a way to do a default redirect in Struts2?
Upvotes: 1
Views: 5731
Reputation: 2138
Go through the examples in the following link, lot of tutorials are given there, using which you can identify your mistakes..
Upvotes: 0
Reputation: 1
Is there no better thing than the meta refresh? Such as in struts there was a jsp:forward... that seems to not work in struts2. I don't know how much I am comfortable with the meta refresh. And don't know different it is than using any java provided redirect, guess I could use that dispatcher class which maybe in the jsp, not sure though.
Upvotes: 0
Reputation: 1773
In my app I just do the following to redirect to a chosen action:
<action name="*">
<result type="redirectAction">
<param name="actionName">portal</param>
</result>
</action>
Just make sure you place this as the last action in your struts.xml configuration file and then it will catch everything that couldn't be matched earlier on.
This way the redirect happens within struts2, this is invisible to the user.
Upvotes: 3
Reputation: 55434
You can specify a welcome-file-list in web.xml and specify index.jsp, for example:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Then in index.jsp, you can put this at the top:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=initLogin.action">
Assuming you have something like this in struts.xml:
<action name="*Login" method="{1}" class="com.abc.LoginAction">
<result name="login">/login.jsp</result>
<result name="register">/register.jsp</result>
<result name="success">/success.jsp</result>
</action>
This will redirect to your LoginAction class with an init action.
So then if I went to http://localhost:8080/MyApp, this is the default action it would go to.
Upvotes: 2