简体   繁体   English

如何设置网站上下文路径

[英]How to set the website context path

I have uploaded my .WAR file on to the server and deployed it. 我已将.WAR文件上传到服务器并进行了部署。 But now the URL by which it is accessible is 但是现在可以访问它的URL是

http://example.com/myapp/ http://example.com/myapp/

where myapp, is the name of the WAR file that I uploaded on to the server. 其中myapp是我上传到服务器上的WAR文件的名称。

I want to know how can I set it to 我想知道如何设置

http://example.com/ http://example.com/

that is, skip the name of the WAR file in the website context path. 也就是说,在网站上下文路径中跳过WAR文件的名称。 I tried setting the path= "/" in context.xml but was of no use. 我尝试在context.xml中设置path =“ /”,但没有用。 Kindly suggest some way to do it. 请提出一些方法。

Thanks in advance 提前致谢

尝试将其称为ROOT.war。

您需要从Webapps目录中删除ROOT.war(假设它仍然存在),并将WAR文件重命名为ROOT.war,然后再上传到Tomcat进行部署,以便将其作为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). 如果将myapp.war放置在其他位置(例如,在tomcat中),则可以在conf \\ Catalina \\ localhost文件夹中创建ROOT.xml(假设您的引擎名为Catalina,主机名为localhost在server.xml中)。 Note the docBase must not point to the webapps folder. 请注意,docBase不得指向webapps文件夹。

<?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. 通常,我不会太担心上下文,而是通过清除默认的ROOT文件夹(除了默认的meta-inf + manifext)并添加重定向的索引jsp来放置从/到上下文的重定向。 ie. 即。 could contain this: 可能包含以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM