Tomcat 6 to Tomcat 7 causes context path to stop cooperating

十年热恋 提交于 2019-12-13 07:15:58

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/14905388/tomcat-6-to-tomcat-7-causes-context-path-to-stop-cooperating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!