Solved

JSP session + cookies + tomcat upgrade

Posted on 2003-11-24
6
337 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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