开发者

How to set the website context path

I have uploaded my .WAR file on to the server and deployed it. But now the URL by which it is accessible is

http://example.com/myapp/

where myapp, is the name of the WAR file that I uploaded on to the server.

I want to know how can I set it to

http://example.com/

that is, skip the name of the WAR file in the website context path. I tried setting the path= "/" in context.xml but was of no use. Kindly suggest some way to do it.

Thanks in adva开发者_C百科nce


Try calling it ROOT.war.


You need to remove ROOT.war (assuming it still exists) from your webapps directory and rename your WAR file to ROOT.war before uploading to Tomcat for deployment so that it gets deployed as the default application on Tomcat.


An alternative:

If you put your myapp.war somewhere else - for instance in the tomcat base - you can create a ROOT.xml in the conf\Catalina\localhost folder (assuming your engine is named Catalina and host named localhost in server.xml). Note the docBase must not point to the webapps folder.

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="..\myapp.war" />

Normally I would not worry too much about the context and just put a redirect from / to the context by clearing out the default ROOT folder (apart from the default meta-inf + manifext) and adding an index jsp that redirects. ie. could contain this:

<%
response.setStatus(301);
response.setHeader("Location", "/myapp" );
response.setHeader("Connection", "close" );
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜