配置 Tomcat 子站点
我对Tomcat的了解为零,我只需要让它进行一些测试,所以如果问题很愚蠢,请原谅我。
我在 Tomcat 7.0.22(Java 1.6、MacOS Lion)中部署了 .war 存档。战争被称为“myapp.war”,因此 Tomcat 正在服务 http://localhost/myapp
(在 /webapps/myapp 中扩展了战争)。我对此很满意。
每当我访问“http://localhost/myapp
”时,页面都不会加载静态文件(例如:对于 /core.css
或 core.css
它查找“http://localhost/core.css
”),而“http://localhost/myapp/
”(<-- 注意斜杠!)可以工作并提供http://localhost/myapp/core.css
。
我的 web.xml:
<web-app>
<servlet>
<servlet-name>org.github.pistacchio.deviantchecker.core/app servlet</servlet-name>
<servlet-class>org.github.pistacchio.deviantchecker.servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.github.pistacchio.deviantchecker.core/app servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
如何正确设置?谢谢
I have zero knowledge about Tomcat and I only need to have it working for some testing, so please forgive me if the questions is stupid.
I deployed a .war archive in Tomcat 7.0.22 (Java 1.6, MacOS Lion). The war is called "myapp.war" and so Tomcat is serving http://localhost/myapp
(having expanded the war in /webapps/myapp). I'm fine with this.
Whenever I visit "http://localhost/myapp
" the page won't load static files (eg: for either /core.css
or core.css
it looks for "http://localhost/core.css
") while "http://localhost/myapp/
" ( <-- note the slash!) works and serves http://localhost/myapp/core.css
.
My web.xml:
<web-app>
<servlet>
<servlet-name>org.github.pistacchio.deviantchecker.core/app servlet</servlet-name>
<servlet-class>org.github.pistacchio.deviantchecker.servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.github.pistacchio.deviantchecker.core/app servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
How to set this up properly? Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只需要它用于测试目的,最简单的解决方案可能是将基本 html 标签添加到网页的头部。
应该可以解决问题。请参阅此链接以获取基本标记的进一步说明
If you only need it working for testing purposes the easiest solution might be to add a base html tag to the head of your webpage.
<base href="http://localhost/myapp/" />
should do the trick.See this link for further explanation of the base tag