File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes I keep on getting a new session (using WLS 10). how do I keep the previous session? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic

I keep on getting a new session (using WLS 10). how do I keep the previous session?

Jay Menorca

Joined: May 16, 2008
Posts: 4
Hello good folks

Btw, I posted this in the weblogic thread under "where have my session attribs gone?"

Pls. refer to my code below... why am I always getting a new session with this code? anything wrong with it? It runs ok in tomcat - no new sessions everytime. In WLS, new session every form submit...sigh...what to do ...pls help

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String title = request.getParameter("subject");
String strTimeStr = request.getParameter("starttime");
int startTime = Integer.parseInt(strTimeStr);
String endTimeStr = request.getParameter("endtime");
int endTime = Integer.parseInt(endTimeStr);
String[] days = request.getParameterValues("day");

HttpSession sess = request.getSession(true);
SchoolSchedule sched = (SchoolSchedule) sess.getAttribute("sched");

if (days != null){
for (int i=0;i<days.length;i++){
String dayString = days[i];
int day;
if(dayString.equalsIgnoreCase("SUN")) day = 0;
else if(dayString.equalsIgnoreCase("MON")) day = 1;
else if(dayString.equalsIgnoreCase("TUE")) day = 2;
else if(dayString.equalsIgnoreCase("WED")) day = 3;
else if(dayString.equalsIgnoreCase("THU")) day = 4;
else if(dayString.equalsIgnoreCase("FRI")) day = 5;
else day = 6;

SchoolClass clazz = new SchoolClass(title, startTime,endTime, day);

request.getSession().setAttribute("sched", sched);
getServletContext().getRequestDispatcher("/Schedule.jsp").forward(request, response);

I added a few more lines in my servlet and I've noticed that for the WLS deployment, I ALWAYS get a new session when I click the form submit button. That's why the stuff that should've been save in the session from the previous form submit is missing.

I only have two elements in my webapp, a jsp page and a servlet. The jsp page has 2 sections, one for getting user inputs and the other part for displaying it. The servlet gets the data inputted in the jsp, massages this data and adds it to an attribute in the session object. The proper thing would be for the data to persist in the session attributes - but it's not behaving like this.

appreciate any suggestions
Ben Souther

Joined: Dec 11, 2004
Posts: 13410


We like there to be only one thread per question.
If you feel you've posted to the wrong forum or if you think that your thread would do better in another one, just ask the moderator of that forum to move it for you. We're always happy to do so.

Having the same question in multiple fora usually ends up wasting the time of the people trying to help you.

Closing this one.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: I keep on getting a new session (using WLS 10). how do I keep the previous session?
It's not a secret anymore!