• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

login and logout using jsp

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...I am using struts2 to create an application and using JSP for the view. Now i have created a welcome page on which there is a login link. Whenever user clicks that link, a login form appears after filling the right credentials user can log into application and the welcome page gets opened again.

Now, i want when the user logs in, instead of login link, logout link should appear and user name gets displayed on login page. When the user logs out the session variables must get cleared and again the login link must appear and user name should get disappeared.

What should i use to do this? Thanks in advance for the help.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like I said here https://coderanch.com/t/554548/Struts/Adding-items-jsp-list-java#2516018, take it one step at time. Break if down into multiple subtasks and try to implement that. If you have problems implementing those tasks then ask specific questions around that, so that it becomes easier for others to help you.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to implement interceptor for that,check this works out for you?

public class LoginInterceptor extends AbstractInterceptor {

private static final String USER = "user";


public String intercept (ActionInvocation invocation) throws Exception {
// Get the action context from the invocation so we can access the
// HttpServletRequest and HttpSession objects.
final ActionContext context = invocation.getInvocationContext ();
HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
HttpSession session = request.getSession (true);

Object user = session.getAttribute (USER);
if (user != null) {
// The user already logged in..
return invocation.invoke (); // send to other interceptor/other page

} else {
return "login"; // if login failed/invalid user redirecting to login page(configure in struts.xml file)
}
}
}
 
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Yatika,

hope this link would help you
http://struts.apache.org/2.2.3.1/docs/simplelogin-with-session.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic