Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JSP session + cookies + tomcat upgrade

Posted on 2003-11-24
6
335 Views
Last Modified: 2010-04-01
Hi,
My intranet application was working fine on tomcat 3.2 but when i try to upgrade to 4.1.24 it goes wrong with the code. Here is my example.
I have a loginaction.java which has following code
...
Cookie cookie =  createCookie(request, "userId", userId);
response.setHeader("realm","../user/login.jsp");
response.sendRedirect("../user/login.jsp");
...
In my jsp i have something like:
...
<%
    String userId=null;
    Cookie[] cook = request.getCookies();
    if( cook!= null){
     for (int k=0; k<cook.length ; k++){          
          if(cook[k].getName().equals("userId"))
               userId= cook[k].getValue();              
               }
            }
     if(userId==null){
     response.setHeader("Back","..");
     response.sendRedirect("..");
     return;          
     }
...

My problem is that the redirect always occurs... in other words the cookies are not set... but it used to work in 3.2?
Any Idea?

Thanks!
0
Comment
Question by:drieske
  • 3
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9811045
is the cookie picked up in jsp pages following that one?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9811068
>  createCookie(request, "userId", userId);

where is this method from?

I thought you had to do:

response.addCookie( new Cookie( "userId", userId ) ) ;
0
 
LVL 35

Accepted Solution

by:
TimYates earned 250 total points
ID: 9811078
So your loginAction.java code you posted becomes:

Cookie cookie = new Cookie( "userId", userId ) ;
response.addCookie( cookie ) ;
response.setHeader("realm","../user/login.jsp");
response.sendRedirect("../user/login.jsp");
0
 
LVL 15

Assisted Solution

by:jimmack
jimmack earned 250 total points
ID: 9818843
>> My problem is that the redirect always occurs

Which redirect?  The one in the JSP (I'm guessing) or the one in loginaction.java (presumably a servlet)?

Is the loginaction servlet definitely being called (in turn redirecting to the login.jsp)?

As Tim asks, what is the code for the createCookie() method?

Are you calling the setMaxAge() method anywhere?

Does this all happen in a single session (the default lifetime of a cookie), or is the problem occurring when a user later goes directly to the login.jsp page?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question