File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes struts2 redirect from action login Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 redirect from action login" Watch "struts2 redirect from action login" New topic
Author

struts2 redirect from action login

Alberto Zolezzi
Greenhorn

Joined: Dec 13, 2010
Posts: 9
Hi all, my first post.......
I have an action login that inserts loggin info into a db and sends the user to a jsp page.
this is how i configure the struts.xml:

<action name="doLogin" class="test.LogindbAction">
<result name="input">Login.jsp</result>
<result name="error">Login.jsp</result>
<result>/WEB-INF/jsp/index.jsp</result>
</action>

This is working fine.

The following step should be to recognize the type of user logged in (admin or normal_user) and send him respectively to index_priv.jsp or index_pub.jsp

At the moment I can get info about the user check if he is an admin or normal_user, but I cannot figure out where to put the redirect ?
Do I need to put this command into the struts.xml ? I was trying to create an interceptor .... am i in the right direction ??

I hope I made myself clear

Alberto


A man who works with his hands is a laborer; a man who works with his hands and his brain is a craftsman; but a man who works with his hands and his brain and his heart is an artist. Louis Nizer.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

You have a user log in and if he is in one role you want him to go to one page and if he is in another role go to another page, right?
I usually create a "home" action that determines which role the user is in and redirects him to the appropriate home page. The login action redirects to the home action if authentication is successful. I'm sure there are other ways to go about it.


[How To Ask Questions On JavaRanch]
Alberto Zolezzi
Greenhorn

Joined: Dec 13, 2010
Posts: 9
this is what I did.....

as you said I used an action login to verify user and then redirect the user to another action.
this is how the struts looks like

<action name="doLogin" class="test.LogindbAction">
<result name="input">Login.jsp</result>
<result name="error">Login.jsp</result>
<result type="redirect">index_select</result>
</action>

the index_select action gets the user role and decides where send the user to

Map session = ActionContext.getContext().getSession();
Object tu = session.get("tipoute");
String s = tu.toString();
if ( s == "admin") {
return "priv";
} else {
return "pub";
}


and this is how I have configure this action in the struts

<action name="index_select" class="test.Index_select">
<result name="priv">/WEB-INF/jsp/index_priv.jsp</result>
<result name="pub">/WEB-INF/jsp/index_pub.jsp</result>
<result name="error">Login.jsp</result>
</action>

Unfortunately the action always goes into the result "pub"

I guess I'm doing something silly, but my experience on this argument is short
thank in advance for any help
Alb
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Have a look at this article on comparing Strings and see if it helps
Alberto Zolezzi
Greenhorn

Joined: Dec 13, 2010
Posts: 9
Joe Ess wrote:Have a look at this article on comparing Strings and see if it helps


this expression worked:

if ( s.equalsIgnoreCase(s1)) ......
......

Thanks Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 redirect from action login