Solved

JSP session + cookies + tomcat upgrade

Posted on 2003-11-24
6
332 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default methods vs abstract class 1 109
servlet cookie finding by name 1 70
error when compiling my project in eclipse luna 30 352
Using Tomcat as raspberry pi java app server 13 141
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

23 Experts available now in Live!

Get 1:1 Help Now