aspose file tools*
The moose likes Struts and the fly likes login and logout using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "login and logout using jsp" Watch "login and logout using jsp" New topic
Author

login and logout using jsp

Yatika Sharma
Greenhorn

Joined: Aug 26, 2011
Posts: 18
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

Joined: Jul 20, 2005
Posts: 10102
    
165

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.


[My Blog] [JavaRanch Journal]
seenu java
Greenhorn

Joined: Oct 03, 2011
Posts: 12
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

Joined: Mar 08, 2011
Posts: 188

hi Yatika,

hope this link would help you
http://struts.apache.org/2.2.3.1/docs/simplelogin-with-session.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: login and logout using jsp