views:

66

answers:

2

Hi all.

My Spring MVC application is runnning on a Tomcat behind an Apache 2 acting as a proxy. I access my app directly in tomcat via an url like http://localhost:8080/myapp. I access my app via proxy with an url like http://localhost/tomcat/myapp.

The second url makes my app behave incorrectly, because it supposes it lives in /myapp context path, but via the proxy it should live in /tomcat/myapp.

Is there a variable in Spring or Servlet API, that holds /tomcat/myapp if I am accessing it via the proxy, and /myapp if I am accessing it directly?

Thanx

A: 

I mean when I redirect to "/index.jsp" it actually redirects to "http://localhost/myapp/index.jsp" instead of "http://localhost/tomcat/myapp/index.jsp"

Redirect to index.jsp instead of /index.jsp

When you redirect to /index.jsp this acts as an absolute url and it gets redirected to myapp/index.jsp. index.jsp is a relative url and will redirect to tomcat/myapp/index.jsp

Faisal Feroz
What in case he intend to redirect from `tomcat/myapp/user/user.html` to `tomcat/myapp/index.html`
Adeel Ansari
And FYI, `/index.html` is not absolute, its also relative but to the context.
Adeel Ansari
Thanx, Adeel, that's exactly what I intend to. Spring MVC app is all about user-friendly urls like /user/add, in which case I think it is wrong to use redirects like "../../index.jsp"
artemb
+1  A: 

I think you need to enable proxy support then. This link might help you or give a little hint in this regards.

Adeel Ansari
Why did somebody -1 this answer? It is correct, though the link should obviously point to http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html.
artemb
I found the solution on the page in the docs about proxy support. I shouldn't proxy from http://proxy/tc/ to http://tomcat:8080/. Instead I should proxy from http://proxy/myapp/ to http://tomcat:8080/myapp/
artemb
@artemb: I am so sorry to provide the wrong link. Actually, I copied few links at that time, and link to proxy page was the last one, and didn't get copied well. Therefore, I ended up pasting the wrong one. But the good thing is, you got it right. Thanks, I modified the post to include the correct link.
Adeel Ansari