• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

problem in session tracking inside my request processor....

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
i am facing trouble while tracking a session inside my struts application,i am using following code snipit

########################################################
public class MyRequestProcessor
extends RequestProcessor {
protected boolean processPreprocess (
HttpServletRequest request,
HttpServletResponse response) {

if(request.getServletPath().equals("/personalLoanIndex.do") ||
request.getServletPath().equals("/PersonalloanIndex.jsp") ){
UserProfile userProfile = new UserProfile();
userProfile.setUserName(request.getParameter("userName"));
userProfile.setUserPassword(request.getParameter("userPassword"));
if(userProfile.doesUserExists()){
HttpSession session = request.getSession();
System.out.println("session id is --------> "+session.getId());
session.setAttribute("userProfile",userProfile);
}

return true;
}


//If user is trying to access login page
// then don't check
if( request.getServletPath().equals("/loginAction.do")
|| request.getServletPath().equals("/login.jsp") )
return true;
//Check if userName attribute is there is session.
//If so, it means user has allready logged in
HttpSession session = request.getSession(false);
System.out.println("###############################################################");
System.out.println("---------> session id "+session.getId());
System.out.println("###############################################################");

if( session != null &&
session.getAttribute("userProfile") != null)
return true;
else{
try{
//If no redirect user to login Page
request.getRequestDispatcher
("/notLogedIn.jsp").forward(request,response);
}catch(Exception ex){
}
}
return false;
}

}



########################################################

here i can not get the same session (session id is shown different) both in the first and second block . in first block i used HttpSession session = request.getSession(); coz i wanted to have current/new session each time this block is executed .in second block i used HttpSession session = request.getSession(false); coz i wanted to have same old session which i previously made in first block .i think there isn't anything wrong with it then where i is problem raised???i am stuck with this error .
NOTE : a strange behavior is that if a try to login my user from login page for the first time i get this problem,but if a try to login the user again from the same window/page i don't get this error and both the sessions from block1 and 2 are same
can you please help me in finding out what i am doing wrong here.
thanks in advance.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic