java - Checking a session value in Struts 2 web application -


this question has answer here:

i creating web application using struts 2. have login page in it. user click login button after entering username , password, credentials checked , if credentials found correct, session created , attributes set , control redirected welcome jsp.

now before welcome.jsp opened, want check, if session attributes set. how in struts 2?

can clear me concept of interceptors. read create interceptors perform function before or after action called. can create interceptor checks if session set, every time before welcome jsp called.

@rickgaurav 1st question. make login action this

<action name="login_action" class="loginaction class">             <result name="success" type="chain">welcomeaction</result>             <result name="input">/index.jsp</result>             <result name="error">/index.jsp</result>         </action> 

wher index.jsp login page

and in login interceptor first make session map in session attribute store

map<string, object> sessionattributes = invocation             .getinvocationcontext().getsession(); 

after check using condition

if (sessionattributes == null                 || sessionattributes.get("username") == null                 || sessionattributes.get("username").equals("")) {              return "login";         }else{ if (!((string) sessionattributes.get("username")).equals(null)){ return invocation.invoke(); }else{ return "login"; } 

for 2nd question assume calling welcomeaction go welcome.jsp page can add action this

<action name="welcomeaction" class="class">         <interceptor-ref name="logininterceptor"></interceptor-ref>                 <result name="login" type="chain">loginaction</result>         <result name="success" >/welcome.jsp</result>      </action> 

hope work you


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -