wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to get login page when session is expired? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get login page when session is expired?" Watch "How to get login page when session is expired?" New topic
Author

How to get login page when session is expired?

prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
When my website's session is expiring it shows an error message like below when trying to access some pages.But for other pages though the session is expired ,when trying to access them ,it prompts to the login page asking user to log again as the session is expired.So i want to eliminate error message for firstly said pages, and make it prompts to login page when they are trying to be accessed as happened in secondly said pages.i'm a beginner So please help me to do this.
This is the error being displaced.I'm using jboss server.Please tell me how to do this.

javax.servlet.ServletException: user name can not be null
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


root cause

java.lang.IllegalArgumentException: user name can not be null
com.atlinkcom.bestcarelab.dal.UserPrivilegeDAL.getUserIdByUsername(UserPrivilegeDAL.java:109)
com.atlinkcom.bestcarelab.manager.UserManager.addUserActivity(UserManager.java:657)
com.atlinkcom.bestcarelab.action.order.GetSchedulesForWelcomeAction.execute(GetSchedulesForWelcomeAction.java:50)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter
[ November 20, 2008: Message edited by: prashan dassanayake ]
Satish Chilukuri
Ranch Hand

Joined: Jun 23, 2005
Posts: 266
It looks like some of your servlets/jsps are handling session expiration cases and some are not. Look at the code for the pages which show the login page on session expiration and see how it is handled. Do the same for other pages.

Also, if user authentication code is duplicated in many places, it is good idea to bring it in one place, preferably in your Controller or in a Filter.
prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
i'm a very first beginner.So can you tell me please in which kind of files these expiration handling codes are being written and where can be these files found.If you can please give me an example code
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
How are you handling the security? Declarative or programatically that is writing code for authorization and authentication.
prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
I said first i'm a learner.So i want to know whether these handlings should be done in java files or jsp files.And what are the commands for doing this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Before anyone can give you meaningful help, you'll need to answer Amol's question. How have you implemented security so far?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
This is halfly built website from somebody.So as a learner I cant understand how the security is handled here by looking the project.I just wanted to correct that error.
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Can you show us the web.xml of this project?
prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
Here it is.


<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>BCL</display-name>
<session-timeout>10</session-timeout>

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>/pages/index.jsp</welcome-file>
</welcome-file-list>

<taglib>
<taglib-uri>/WEB-INF/tlds/struts-layout.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-layout.tld</taglib-location>
</taglib>

</web-app>
prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
Thanks all for replying.Bye!
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Looks like secutity is handled progmatically can you post the code for
getUserIdByUsername method of com.atlinkcom.bestcarelab.dal.UserPrivilegeDAL
in Mkumar
Greenhorn

Joined: Sep 08, 2008
Posts: 20
To get login page..you need to write a servlet or any controller and check for invalidate seesion ..if it is not live ..redirect to login page from controller it self, and also define this servlet with <load-on-startup> in web.xml..

hope you will get result. - Manoj
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2712
    
    5

"in Mkumar " please see your private messages for an important administrative matter.


SCJP, SCWCD.
|Asking Good Questions|
prashan dassanayake
Greenhorn

Joined: Nov 07, 2008
Posts: 23
Here it is Amol,


[BPSouther: Added code tags]
[ November 21, 2008: Message edited by: Ben Souther ]
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Now if we look at the code posted by you the the problem lies here



Which means the parameter passed to this method itself is null.
I would like you to do some analysis now,

Look at these methods addUserActivity() of
com.atlinkcom.bestcarelab.manager.UserManager
and
execute of this action
com.atlinkcom.bestcarelab.action.order.GetSchedulesForWelcomeAction

check where the user variable is instanciated and assigned a value, should be somewhere in these two methods above i reckon. Put some log messages in these two methods at meaningful places and try executing it again. Now access the pages where you are getting this exception and then those where it is directed to login page on session expiry.
Check for these things
Is this action and UserManager class coming in picture for the pages
where it is directed to login page on session expiry?

If yes, check why this username is not null in that case.

Please post back if you have any doubts or problems in doing this.
[ November 20, 2008: Message edited by: Amol Nayak ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get login page when session is expired?
 
Similar Threads
Dispatch Error Action
Unsupported major minor version error urgent
Unable to compile class for JSP
java.lang.IllegalArgumentException: No bean specified
Unable to compile class for JSP