Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts2 redirect from action login

 
Alberto Zolezzi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alberto Zolezzi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this article on comparing Strings and see if it helps
 
Alberto Zolezzi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic