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

login and logout using jsp

 
Yatika Sharma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said here http://www.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.
 
seenu java
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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)
}
}
}
 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic