0

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

  1. 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
  2. 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

Community
  • 1
  • 1
Shaun Abram
  • 261
  • 1
  • 4
  • 9

2 Answers2

2

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 :

<c:url value="/style.css" var="url" />
<link rel="stylesheet" href="${url}" type="text/css">

or

<link rel="stylesheet" href="${pageContext.request.contextPath}/style.css" type="text/css">

see also Spring MVC Request URLs in JSP

Community
  • 1
  • 1
nicolas de loof
  • 2,558
  • 1
  • 11
  • 10
  • Thanks for your answer (and link) Nicolas. swashbuck1r's answer was also useful. As advised, the solution was simply changing my form action from
    to
    Many thanks, Shaun
    – Shaun Abram Sep 15 '12 at 15:54
0

CloudBees runs your applications using a ROOT context path [/]. You have at least two options to make your app work in both your local environment and the Cloud environment:

  • Run your app locally using a ROOT context (by deploying the app to webapps/ROOT or webapos/ROOT.war)
  • Change the URL used to generate your form to construct the form's action path using request.getContextPath()
swashbuck1r
  • 378
  • 1
  • 3