Thank you Dave, feel like have to spend some time reading some books (which I really hate to do) on struts like struts 2 in action :-(
newton.dave wrote: > > It would be much cleaner to put that kind of logic into an interceptor > rather than in a prepare() method. It would cut down significantly on > code duplication. > > Dave > > sagsai wrote: >> Hello friends, >> I have very little experience in struts 2 & I have this typical >> requirement >> where I feel that I have to redirect form the prepare() method when the >> user >> is not logged in (by checking whether some session entries present or >> not). >> Actually I am trying to avoid repetitive session checking & redirecting >> at >> the beginning of every action method, for example >> public String listUsers() throes Exception >> { >> //if (session.get("userType") != null && >> session.get("userType").equals("admin")) >> //then show the result >> //otherwise redirect to the login page >> } >> >> public String viewDetails() throes Exception >> { >> //again code for the same checking >> } >> so I thought that since the prepare() method is being called every time >> some >> action is being mapped to a method in this class so why not put the code >> for >> checking & redirecting inside of prepare >> like, >> public void prepare() throws Exception >> { >> //if the user is not logged in >> //redirect to the login page >> } >> >> But the problem is that I cannot return any string (which I can specify >> as >> result of type "redirect-action" in the struts.xml file)since this >> function >> has return type void also I could not find any method to redirect >> forcibly. >> >> So, my question is whether it is possible to redirect form any method >> which >> has not been mapped as an action at all? >> if it can be done then how to do it? >> >> Any ideas regarding this problem would really help. >> Thanks in advance > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > -- View this message in context: http://www.nabble.com/how-to-redirect-from-prepare%28%29-method-in-struts-2-tp21643785p21644051.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org