• 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

Problem with session timeout

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,
I have wrote the JSF Code to design the login page.But i have faced one problem in the code.I have time out filter in my code.Whenever i tried to run the code at first time the session is timed out and it redirect to the session time out page.What is the reason for this bug? and How can i resolve this problem?
My Web.xml code is below,

Thanks in advance.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can we debug code we cannot see?
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,
Now i attached the code here.Take a look at it and try to resolve my problem.
Thanks.


Try to resolve it.
Thanks.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That counter is an instance variable and that will not fly. Filters are just like Servlets and the same instance will very probably be reused for several sessions/requests.

ram.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see this code this may hep you

In web.xml do like this

<filter>
<filter-name>SessionExpireCheck</filter-name>
<filter-class>ManualFilters.SessionExpireFilter</filter-class>
<init-param>
<param-name>redirect</param-name>
<param-value>/Expire.jsp</param-value>
</init-param>
<init-param>
<param-name>LoginPage</param-name>
<param-value>/Login.jsp</param-value>
</init-param>
</filter>


<filter-mapping>
<filter-name>SessionExpireCheck</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>


here login page is your login page so that we can skip login page session checking



In your sessionExpireFileter do like this

public class SessionExpireFilter implements Filter {

private HttpSession session;
private String redirect = null;
private String LoginPage = null;
private FilterConfig filterconfig = null;


public void doFilter(ServletRequest req, ServletResponse res, FilterChain filter_chain) throws IOException, ServletException {
redirect = filterconfig.getInitParameter("redirect");
LoginPage = filterconfig.getInitParameter("LoginPage");
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
session = request.getSession(false);
if (session != null && !session.isNew() && session.getAttribute("ok") !=null ) {
filter_chain.doFilter(req, res);
}
else
{
if(request.getServletPath().equals(LoginPage))
{
session = request.getSession(true);
session.setAttribute("ok", "ok");
filter_chain.doFilter(req, res);
}
else
{
RequestDispatcher requestDispatcher = request.getRequestDispatcher(redirect);
requestDispatcher.forward(request, response);
}
}

}

public void init(FilterConfig conf) throws ServletException {
setFilterConfig(conf);
}

public void destroy() {

}

public FilterConfig getFilterConfig() {
return filterconfig;
}

public void setFilterConfig(FilterConfig filterconfig) {
this.filterconfig = filterconfig;
}


}
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ram,
You are correct.But i have used flag for skip the filter for first request.Because if i don't skip, the filter is executed and send my control to time-out page.Please have a look at it and try to resolve my problem.
Thanks for your reply.
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guptha,
Thanks for your reply.But my problem is not resolved.The bug is not fixed.Anyother way to fix this bug?
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But i have used flag for skip the filter for first request.Because if i don't skip, the filter is executed and send my control to time-out page.Please have a look at it and try to resolve my problem.



It will only skip the first request from the first user that logs in after the server is brought up. You have to think of another strategy. What is it that you are trying to achieve?

ram.

 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ram,
Thanks for your valuable suggestion.But i can't find another way.If you have any idea please share with me.
Thanks.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is it that you are trying to achieve?

ram.
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ram,

Whenever i try to run with my (url)code,At first time(i.e.)for my first request it redirect to logout page due to session expired.But I trying to go to the login page for my first request.


 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muneeswaran Balasubramanian wrote:Hi Guptha,
Thanks for your reply.But my problem is not resolved.The bug is not fixed.Anyother way to fix this bug?



The code posted by GG is something I expect would work -- whats the problem you face when you use that code?
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sam,
I have tried to run the code posted by GG.But it also make the same effect.On the time of run the code,the filter is called before the session is created.So it redirect to the session expired page.
What can i do?I need your guidance.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't redirect if there's no session? Create a session if there isn't one?
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code

if(request.getServletPath().equals(LoginPage))
{
session = request.getSession(true);
session.setAttribute("ok", "ok");
filter_chain.doFilter(req, res);

should redirect the page 'Login.jsp' to the proper page. Ummm your login page is called Login.jsp right?

**********Configured In web.xml here ***************

<init-param>
<param-name>LoginPage</param-name>
<param-value>/Login.jsp</param-value>
</init-param>
 
Ggaurav Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sam Mercs .....

Yes LoginPage is the LoginPage.jsp ........

if(request.getServletPath().equals(LoginPage))
{
session = request.getSession(true);
session.setAttribute("ok", "ok");
filter_chain.doFilter(req, res);


this code means whenever the request is coming from login.jsp a new session is created and one attribute is set into the session "ok" . and for other jsp pages we are checking for session and check for the attribute "ok". In case anyone is facing any issues please call me on 09324053008. I am using this filter for the last 45 day and i m not facing any issues .
 
Ggaurav Gupta
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Muneeswaran Balasubramanian,

Like to tell you that please make the entries in web.xml.

put your LoginPage as the first page from where you want that the session should be created or from the page where first request is made.
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,
I have resolved the problem.Thanks to all for your guidance.
Cheers Munees
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic