问题
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:
- 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
) - If you have an exploded application, create a folder
MyApplication
insidewebapps
and drop the application contents there (again, nocontext.xml
).
If you really need to keep your application outside of webapps
:
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">
- 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