eclipse tomcat 的 URL 问题包括项目名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9160241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:40:46  来源:igfitidea点击:

URL issue with tomcat include project name

eclipsetomcatservletsurl-rewriting

提问by Ankur Loriya

I am using Eclipse for J2EE project... one device send request to my side and url like

我正在将 Eclipse 用于 J2EE 项目......一个设备向我发送请求,网址如下

http://myIP:myPort/corporationweb/Controller

/corporationweb/Controlleris fixed we can't change it because it made on device

/corporationweb/Controller已修复,我们无法更改它,因为它是在设备上制作的

my project name in eclipse is "VirtualTest" but here tomcat include project name if i mapping any servlet, /corporationweb/ControllerURL like

我在 Eclipse 中的项目名称是“ VirtualTest”,但如果我映射任何 servlet、/corporationweb/ControllerURL 等,那么这里的 tomcat 包括项目名称

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
  • 任何我可以直接映射 servlet 所以 URL 像 http://localhost:8080/corporationweb/Controller
  • 任何 URL 重写技术..
  • 作为我项目的默认应用程序

回答by BalusC

Rightclick project in Eclipse, choose Properties, go to Web Project Settingsand set Context rootto /.

在 Eclipse 中右键单击项目,选择Properties,转到Web Project Settings并将Context root设置为/.

enter image description here

在此处输入图片说明

This will let Eclipse deploy the project on context root instead of project name (which is the default).

这将使 Eclipse 在上下文根而不是项目名称(这是默认值)上部署项目。



Unrelatedto the concrete problem, you really need to ensure that your application is written the way so that it does not careon 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.

具体问题无关,您确实需要确保您的应用程序的编写方式使其不关心应用程序部署在哪个上下文路径上。这是特定于服务器的设置,无法从您的项目内部进行控制。利用HttpServletRequest#getContextPath()聪明的方式。

回答by andrew Yang

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:

如果您想让“VirtualTest”作为您项目的默认应用程序,并且不在 URL 中显示此名称,您只需将项目名称更改为“root”,这是默认应用程序的特殊名称。
您的网址将类似于:

http://localhost:8080/corporationweb/Controller

回答by Sidharth

If you are using Eclipse. Go to server and remove the unwanted project which are Synchronized, then restart your server. Worked for me

如果您使用的是 Eclipse。转到服务器并删除同步的不需要的项目,然后重新启动服务器。对我来说有效