I have a web app that I run locally in tomcat and which I have also deployed to Cloudbees. However, I am having some problems with cloudbees using a virtual host versus my local tomcat using a context path.
I access my local tomcat app via
http://localhost:8080/SpringMVC
In cloudbees, I access it via
So far so good, but the problem is when I try to do a submit. Locally, this submits successfully to
http://localhost:8080/SpringMVC/HelloWorld
But on cloudbees, it tries (and fails) to submit to
http://springmvc.shaunabram.cloudbees.net/SpringMVC/HelloWorld
If I manually modify the browser URL to
http://springmvc.shaunabram.cloudbees.net/HelloWorld
it all works fine.
I saw a similar problem posted here, but the suggested solution was to
- update the web.xml to use the prefix path (e.g. I think
/SpringMVC in my case), but this would break my local tomcat version, or - deploy the app as an EAR file with an application.xml – but
migrating to an EE container like tomcat EE or JBoss will be a much
bigger task.
I had thought the solution might be to use the CloudBees Web Configuration File to somehow configure the app to use (something like) http://springmvc.shaunabram.cloudbees.net/SpringMVC as my base url, but I can’t see any examples of that (all CloudBees Web Configuration File examples seem to be used for environment specific DataSources).
Any help greatly appreciated!
Shaun
Web application should never use absolute path and always build URL using ServletContext.getContextPath(). I wonder you hit this issue, assuming you use SpringMVC that handles this for you.
Or maybe you hard-coded some resources path, but should use to generate the adequate path, or a scriptlet to append context Path :
or
see also Spring MVC Request URLs in JSP