Hi All, Yes, I know you're thinking this topic has been well-covered. I searched the Saloon archives and did find the answer to my problem. I'm looking for suggestions as to how to resolve it. First, the problem:
I have a jsp page, page1.jsp, which submits a request to a Servlet, Servlet1. Servlet1 processes the request, then sends a reponse to a pop-up window, pop-up1.jsp. Now, when Servlet1 sends the reponse to pop-up1.jsp, pop-up1.jsp cannot access session attributes which were set by Servlet1 -- because pop-up1.jsp has a new session.
At first I thought this was because Tomcat assigns new sessions when a window.open() call is made (this was discussed in previous posts as a possible problem). However, this is not the case. I can use pop-ups and still maintain the same session ID.
The other issue I found in previous posts is the fact that Tomcat sees context changes as new sessions. For instance, I have my Servlet in the following directory: /var/www/html/WEB-INF/classes/webUtils/Servlet1
The jsp pages are in this directory (within the myApp directory): /var/www/html/myApp/
My web hosting service is using an Apache server with Tomcat to handle Servlets/jsp, so I had to set it up this way.
So, apparently the path change is causing Tomcat to create a new session. Now I can generate all the HTML in my Servlet, in which case, I won't need to set session attributes, but I really don't want to do this.
Anyone have any suggestions as to how to maintain the session?
How about transferring all your Servlet processing to a controller JSP? A bit crap, I know, but that would circumnavigate the problem, wouldn't it? An alternative being to coerce your web host to put JSPs and Servlets under the same root context...
Would you tell me how your servlet is accessing the popup.jsp? As mentioned in the previous post, pageContext.forward in jsp would maintain the session but I'm wondering how your doing it in the servlet.
I do not understand this. How does having Apache front Tomcat force you to put your servlets in a different web application than the JSPs?
Why cannot your servlets be placed in /var/www/html/myApp/WEB-INF/classes/webUtils/Servlet1?
I'm not fully sure as of yet. My web hosting service advised me that the Servlets needed to be placed in root WEB-INF folder. This has been a major pain, as my app is no longer nicely encapsulated within the app root directory. I did it this way, and in the meanwhile I'm investigating how to set it up like I do on a Tomcat standalone server (with everything in the same directory).
I'm looking at the server.xml file for Tomcat, and it has the following context: <Context path="" docBase="/home/virtual/site20/fst/var/www/html" crossContext="false" reloadable="true />
Now, I would assume, if I have a web app, myApp, and I place it in /var/www/html/, that Tomcat will recognize the myApp context, in which case I can place all my Servlets in myApp/WEB-INF/classes/webUtils/. But it's not working. I don't think it's recognizing the myApp context. In my jsp pages, when I send a request for a Servlet, I form the url as follows: "/servlet/Servlet1". Hence, it goes out of myApp context, to the ROOT directory and accesses the Servlet. Normally, when I'm running my own server, I form the url: "servlet/Servlet1", so it remains in the myApp context and accesses the Servlet in the myApp WEB-INF directory.
not fully sure as of yet. My web hosting service advised me that the Servlets needed to be placed in root WEB-INF folder.
Ridiculous. Either you are misunderstanding what they are saying, or they are complete buffoons.
This has been a major pain,
Unacceptable and needless.
Now, I would assume, if I have a web app, myApp, and I place it in /var/www/html/, that Tomcat will recognize the myApp context,
Do you have a web.xml in the WEB-INF folder? You need at least a minimal one. [ August 06, 2004: Message edited by: Bear Bibeault ]
Joined: Apr 16, 2004
Here's the response from Oxxus web hosting:
Anyway, where did you put your servlets? If it's tomcat4/webapps/ they WON'T work, you must put them to your var/www/html/WEB-INF/ directory.
So as long as the Servlets are in the ROOT WEB-INF, they work fine. I do have a web.xml in myApp/WEB-INF with the correct Servlet mappings and everything. This app works fine on stand-alone Tomcat servers. But something about how Oxxus has Tomcat configured (and I can't see it in the server.xml), is preventing myApp from loading. I've had other issues with Tomcat not starting properly on Oxxus, so I may be in the market for a new web host.
Thanks for the replies. [ August 06, 2004: Message edited by: Jeffrey Hunter ]
If you are paying for the hosting and they are unwilling to help you set up a real web application in other than the default context, I'd not only change hosting, but demand a refund.
Are you sure they understand that you are trying to set up an app in a new context? I find it hard to believe that they could be so inept.
Joined: Apr 16, 2004
They do have a 30-day money back guarantee, so I will take advantage of it if necessary. Their support structure is ill-fitted to answer specific questions regarding Tomcat/Servlet technology. It took about 5 question and answer rounds before I finally had enough info to tweek my Servlets and get them to work on their server -- but, like you said, it's not a good solution, at all.
Oh well, at least I know I'm not asking them the wrong questions.
Joined: Apr 16, 2004
Just a follow-up should anyone dig this thread up on a search. Apparently when using Apache and Tomcat together, some extra configuration must take place in Apache in order to load any new "context" into your webapps directory.
So, in order to get my web app to work, I had to email my web hosting service and give them the name of my app, so they could load the context into the Apache-Tomcat connector.
A point that was not well-explained in the hosting plan documentation. Oh well, it's working.
I see that your problem is solved, but here's some info you may find useful anyway.
On my Suse box, I have these in my /etc/apache2/conf.d/tomcat_jk.conf file, and that's all you need to setup a webapp on a new context
# The following line makes apache aware of the location of # the /examples context Alias /examples "/opt/jakarta/tomcat/webapps/examples" <Directory "/opt/jakarta/tomcat/webapps/examples"> Options Indexes FollowSymLinks allow from all </Directory>
# The following line mounts all JSP files and the /servlet/ uri to tomcat JkMount /examples/servlet/* ajp13 JkMount /examples/*.jsp ajp13
# The following line prohibits users from directly accessing WEB-INF <Location "/examples/WEB-INF/"> AllowOverride None deny from all </Location>
The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny GillTweets
Joined: Apr 16, 2004
Thanks, Sonny. I'm sure eventually I will have to configure an Apache-Tomcat system, and right now all I'm used to is Tomcat standalone, so thanks for your input.