943,832 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 2317
  • JSP RSS
Nov 18th, 2008
0

JSP/Java Servlet Apache+Tomcat Sessions

Expand Post »
Hello,

This is my first post here. I appreciate any help you guys can give me.

I'm having some issues with the technologies listed in the title. I've narrowed this down to a Apache/Tomcat configuration issue (I'm leaning towards tomcat issue).

First of all, my setup:

Apache 2.2.10 -- The server is set to use C:\serverroot as it's base.
Tomcat 6.0.18 -- Set to take any requests from apache's base that end in .jsp and process them. Also has a webapp I made called fap (which is a basically a login gateway).

I can successfully trigger the webapp and send it data via form post. So where's the problem right?

Well after the servlet verifies the username/password I use:

java Syntax (Toggle Plain Text)
  1. ...
  2. session.setAttribute("enick", "blarg");
  3. ...

I'm using a literal value for testing so that I don't have to worry about maybe the variable being set incorrectly. Then I redirect the user back to the main page where the jsp is something like this:

jsp Syntax (Toggle Plain Text)
  1. ...
  2. <%
  3. out.print(session.getAttribute("enick"));
  4. %>
  5. ...

Now this always comes back null. I tried using setAttribute right before the display code in the main page. I load the page, then remove the setAttribute, and getAttribute still returns "blarg" as it should. So I thought maybe it was the servlet, so I had not redirect, and then display the value of getAttribute("enick") right after setting it. That works as well.

Then I remembered once while I was still setting up and Tomcat I saw a SESSIONS.ser file. So I went to the Tomcat folder and found the work folder. At some point in the tree structure under the "work" folder there is a "localhost" folder.

The "localhost" folder has 2 subfolders, "fap" and "_". Each has it's own SESSIONS.ser file. Using a hex editor I found the session ID that I was trying to test in BOTH of the SESSIONS files. However only the fap\SESSIONS.ser had the information I had set in the servlet. So to do a test, I copied this SESSIONS.ser over the _\SESSIONS.ser and then turned tomcat on and restarted apache. Low and behold when I loaded the main page again it showed the value the servlet had previously shown.

So I'm led to believe that for some reason the sessions aren't being shared by the JSPs in my root, and the servlets in my webapp. How do I get them to share the same SESSIONS, or should I just get all of them in the servlet and use "web.xml" to make the webapp handle everything under "/" instead of "/fap/".




~0
Last edited by peter_budo; Nov 18th, 2008 at 5:05 am. Reason: Code tag correction, use [code] or [code=java]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
0sinner is offline Offline
3 posts
since Nov 2008
Nov 18th, 2008
0

Re: JSP/Java Servlet Apache+Tomcat Sessions

Sorry.. In my first post where I wrote:

jsp Syntax (Toggle Plain Text)
  1. ...
  2. <%
  3. out.print(session.getAttribute("enick"));
  4. %>
  5. ...

It's actually cast to a string before it's printed:

jsp Syntax (Toggle Plain Text)
  1. ...
  2. <%
  3. out.print((String)session.getAttribute("enick"));
  4. %>
  5. ...
Last edited by peter_budo; Nov 18th, 2008 at 5:04 am. Reason: Code tag correction, use [code] or [code=java]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
0sinner is offline Offline
3 posts
since Nov 2008
Nov 18th, 2008
0

Re: JSP/Java Servlet Apache+Tomcat Sessions

I guess no one else is having this problem?

I'll wait a little more for a reply, but I appreciate any help you guys can provide. In the meantime I think I'll have all HTTP requests to "/" go directly to the webapp and hope that works.

If you guys have any hint as to how to fix this, or even if it is fixable I'd appreciate it.



Thanks a bunch
~0
Last edited by 0sinner; Nov 18th, 2008 at 11:20 am. Reason: Spelling/grammar
Reputation Points: 10
Solved Threads: 0
Newbie Poster
0sinner is offline Offline
3 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Help in javascript-jsp
Next Thread in JSP Forum Timeline: How to load array in JSP getAttribute





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC