Question

I have a webapp that is working swimmingly in Tomcat 6. Let's say it's running on server:8282/MyApplication. I have a context xml that looks like this:

<Context crossContext="true"
         debug="5"
         docBase="MyApplication"
         path="MyApplication"
         reloadable="true">

In my application, my links look like

server:8282/MyApplication/myAction.do?params=blah

When I switch it to Tomcat 7, it seems to change the link to:

server8282/myAction.do?params=blah

I haven't changed -anything- in the application, it's the same code in both places. Is there some global setting I can change to get that "MyApplication" back in?

Edit: the code that generates the link is, as an example,:

<a href="<%=request.getContextPath() %>/myAction.do?params=blah">do the blah</a>
Was it helpful?

Solution

Seems like something is wrong with your deploying process, and for some reason Tomcat is trying to serve your application at the root of the server, because of that your ${pageContext.request.contextPath} is returning empty.

Since I'm not sure of your exactly deployment requirements, try one of the following procedures. Just to be sure and avoid configuration conflicts, do it on a brand new Tomcat 7 installation:

  1. If you have a MyApplication.war file just drop it at <CATALINA_HOME>\webapps, do not use any context files (be ware of context files inside the war file, i.e., /META-INF/context.xml)
  2. If you have an exploded application, create a folder MyApplication inside webapps and drop the application contents there (again, no context.xml).

If you really need to keep your application outside of webapps:

  1. Add a new Context element to <CATALINA_HOME>\conf\server.xml inside <Host>:

    <Context path="/MyApplication"
             docBase="/absolute/physical/path/to/MyApplication" 
             reloadable="true"
             crossContext="true">
    
  2. Alternatively create a MyApplication.xml file in <CATALINA_HOME>\Catalina\localhost with the content mentioned above.

For further info refer to The Context Container documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top