tomcat 的 URL 问题包含项目名称
我正在使用 Eclipse 进行 J2EE 项目... 一台设备向我这边发送请求,并且像
http://myIP:myPort/corporationweb/Controller
/corporationweb/Controller
这样的 url 已修复,我们无法更改它,因为它在设备上使
我在 eclipse 中的项目名称为“VirtualTest
”但这里 tomcat 包括项目名称,如果我映射任何 servlet,/corporationweb/Controller
URL 就像
http://localhost:8080/VirtualTest/corporationweb/Controller
我需要打开页面而不更改项目名称
- 任何我可以直接映射 servlet 所以 URL 像
http://localhost:8080/corporationweb/Controller
- 任何 URL 重写技术..
- 作为我的项目的默认应用程序
I am using Eclipse for J2EE project...
one device send request to my side and url like
http://myIP:myPort/corporationweb/Controller
/corporationweb/Controller
is fixed we can't change it because it made on device
my project name in eclipse is "VirtualTest
" but here tomcat include project name if i mapping any servlet, /corporationweb/Controller
URL like
http://localhost:8080/VirtualTest/corporationweb/Controller
I need page open without change project name
- any i can mapping servlet directly so URL like
http://localhost:8080/corporationweb/Controller
- any URL rewriting technique..
- make as default application for my project
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Eclipse 中右键单击项目,选择“属性”,转到“Web 项目设置”,并将“上下文根”设置为“/”。
这将使 Eclipse 将项目部署在上下文根目录而不是项目名称(这是默认值)上。
与具体问题无关,您确实需要确保应用程序的编写方式使其不关心应用程序部署在哪个上下文路径上。这是特定于服务器的设置,无法从项目内部控制。利用
HttpServletRequest#getContextPath()< /code>
聪明的方式。
Rightclick project in Eclipse, choose Properties, go to Web Project Settings and set Context root to
/
.This will let Eclipse deploy the project on context root instead of project name (which is the default).
Unrelated to the concrete problem, you really need to ensure that your application is written the way so that it does not care on which context path the application is been deployed. This is namely a server specific setting which is not controllable from inside your project. Make use of
HttpServletRequest#getContextPath()
the smart way.如果您想将“VirtualTest”设置为项目的默认应用程序,并且不在 URL 中显示此名称,您只需将项目名称更改为“root”,这是默认应用程序的特殊名称。
您的网址将类似于:
If you want to make "VirtualTest" as default application for your project, and not showing this name in URL, you can simply change project name to "root", which is a special name for the default application.
Your URL will be like:
如果您使用的是 Eclipse。转到服务器并删除已同步的不需要的项目,然后重新启动服务器。为我工作
If you are using Eclipse. Go to server and remove the unwanted project which are Synchronized, then restart your server. Worked for me