Forums Register Login

Why am I always getting a new session *

+Pie Number of slices to send: Send
* - when my webapp is deployed in Weblogic server 10

Hello good folks

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);
sched.addClass(clazz);
}
}

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. ^_^
+Pie Number of slices to send: Send
Has your container been configured not to use cookies for session handling?
If so, then you would need to urlEncode all of your links, hrefs, src's, and form actions in order for sessions to work.
+Pie Number of slices to send: Send
Please use real words when posting to the forums. Abbreviations such as "pls" in place of "please" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
+Pie Number of slices to send: Send
I dont think my WLS 10 is currently using cookies for session tracking. I tried to do that URL rewriting / URL encoding both in my servlet and my jsp, but i'm still getting a new session at every form submit.

here are some code snippets:

//-----------------servlet------------------------

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

if (sched == null) {
sched = new SchoolSchedule();
}

// here I add somthing to the SchoolSched - it's an Arraylist of
// some class so i just add objects to it

sched.addClass(clazz);

request.getSession().setAttribute("sched", sched);

//below to encode URL - Am I doing this correctly?
response.encodeURL("/Schedule.jsp");
getServletContext().getRequestDispatcher("/Schedule.jsp").forward(request,response);


//-----------------DD------------------------
<servlet>
<servlet-name>ScheduleServlet</servlet-name>
<servlet-class>
com.jay.schoolSched.controller.ScheduleServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ScheduleServlet</servlet-name>
<url-pattern>/Scheduler</url-pattern>
</servlet-mapping>

//-----------------Schedule.jsp------------------------
below is for the URL rewriting..uhm i'm also not sure if this is the way
to do this. Is it? When I click this one, it should go back to the servlet - add what ever data i indicated to the session (i assume that this should be the current session so it still has the value from the previous setAttribute()) and dispatches it again to this jsp for display.

<form action="<c:url value='/Scheduler' />" method="post">


//-------------------------------------------------------

Really appreciate your help. ^_^ When I get this ironed out I'll have pizza sent from here in singapore to whereever you are ^_^
+Pie Number of slices to send: Send
Why don't you try testing with a simpler JSP?



Keep clicking the link.
If you see the same id every time, then you know session based cookies are working. If not, they they might be disabled.
Try wrapping the URL with urlEncode and try again.
+Pie Number of slices to send: Send
Tried it, for tomcat, i always get the same session ID. For the WLS deployment, i always get a new one.

uhm... how do you exactly wrap the URL using urlencode? I take it I should apply the url encode to thelink in the jsp right?

And for the case of my app, I should apply the url encode in the form action attribute?
Would this (code below) be the way to do it if my jsp passes control to a servlet with urlpatter "/Scheduler" ?

<form action="<c:url value='/Scheduler' />" method="post">

Appreciate your suggestions...looking forward to more tips
+Pie Number of slices to send: Send
That looks good.
The URL rewriting won't get done unless the container can't use the default session handling mechanism (usually cookies).

So, if I add an encoded url like this:


The url will just be: /asdf

Once I disable cookies in Firefox and refresh the page, it looks like:


Session ID: 4650DD23BC74D7FB0690359F143121CC
click me
SomeURL: /asdf;jsessionid=4650DD23BC74D7FB0690359F143121CC





Just a thought, it might be less work to figure out why Websphere is configured not to use cookies for session handling and then (if there is no good reason) get your admin to configure it to do so.

It's a lot of work to find every link in an app and wrap it with c:url.
+Pie Number of slices to send: Send
try to change the HttpSession sess = request.getSession(true);

putit with no arguments: HttpSession sess = request.getSession();
+Pie Number of slices to send: Send
Hi Jay,
One of the reason might be your JSP is not participating in a Session.

Just copy this line to your JSP

<%@ page session="true" %>

Regards,
+Pie Number of slices to send: Send
when url is created dynamically, wen can do like this...

here varname is variable, and the link will open in a new page.

<%String url="abc.jsp?ticket_number=" + varname ; %>
<a href=<c:url value="<%=url%>"/> target="_blank">
+Pie Number of slices to send: Send
Hi,

Probably you may try this. I tried this before and it worked for me.

I'm not sure if it is what you are looking for. So don't blame me



This way you can ensure that either you would use the existing session if present or go for a new session.
+Pie Number of slices to send: Send
 

Originally posted by Ben Souther:
Just a thought, it might be less work to figure out why Websphere is configured not to use cookies for session handling and then (if there is no good reason) get your admin to configure it to do so.

It's a lot of work to find every link in an app and wrap it with c:url.



My philosophy is always to pass all URLs through the c:url pattern any way so the app doesn't break when a client doesn't use cookies.

Easy(ier) to say when you are starting an application rather than working on an existing app of course...
and POOF! You're gone! But look, this tiny ad is still here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6978 times.
Similar Threads
Grid size limit
getting dynaction form property twice after few if and few eror
strange.. !! plz help me..
IllegalStateException in forward
I keep on getting a new session (using WLS 10). how do I keep the previous session?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:32:29.