testing test
testing test

Reputation: 61

Where is Spring MVC context path set?

I am not sure how context path is set. When I rename my .war file in tomcat on autodeploy, the web page goes to localhost:8080/newDirectory as expected, however for some reason wherever there's a call to pageContext.request.contextPath in a Spring based page, it still returns the old context path.

I tried to override the context path by setting:

<context path="/newDirectory" docBase="appName" override="true"></context>

in server.xml but it doesn't work.

My question is, where does Spring read its context path from? I used Maven and I did see there's a

<appContext>/${project.artifactId}</appContext>

in the pom.xml, does this mean I need to rename the artifactId to newDirectory ?

I have also tried adding that <context path="/newDirectory"...> in /META-INF/context.xml (which now I know will be ignored anyway due to my server.xml changes).

Thanks in advance for your answer.

Upvotes: 6

Views: 7459

Answers (2)

bifulcoluigi
bifulcoluigi

Reputation: 51

It not depends on Spring maybe you are using a maven plugin to build your war that reads the appContext property. You can read about definig ServletContext in this thread.

Upvotes: 1

Sunil Kumar
Sunil Kumar

Reputation: 5657

Every PageRequest will get current HttpServletRequest object and get context path of current request and append your .jsp (that will work even if the context-path this resource is accessed at changes).

Eg,

if you have war file as MyCompany.war and having a page with ${pageContext.request.contextPath}/MyJspPage.jsp.

Then your context path is http://abc/MyCompany and it works as http://abc/MyCompany/MyJspPage.jsp.

Suppose if you change your war file as OurCompany.war,

then your context path changes to http://abc/OurCompany and Jsp will work as http://abc/OurCompany/MyJspPage.jsp.

It means context path will change automatically to name of the application(War file name) with out any changes.

In your case,after renaming war file name with newDirectory,your webserver will deploy newDirectory application but still newDirectory application exist in the web server.I think you should delete old application from webapp and then check by reloading your newDirectory application.

Upvotes: 0

Related Questions