Solved

JSP session + cookies + tomcat upgrade

Posted on 2003-11-24
6
331 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
Comment Utility
is the cookie picked up in jsp pages following that one?
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
>  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
Comment Utility
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
Comment Utility
>> 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
library class in java 1 89
difference between member and local variables. 29 121
Java Exception example issues 11 83
maven project jars 7 46
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now