使用 Tomcat 和 Eclipse 进行 Servlet 和 JSP 文件的 URL 映射

发布于 2024-12-28 10:56:05 字数 633 浏览 0 评论 0原文

我在 Eclipse 中有一个 Web 应用程序项目,配置为部署到本地 Tomcat 服务器。我们将该 Web 应用程序命名为 Blah。这里有两个问题——我一定错过了一些非常简单的东西,但是我找不到一种简单的方法来在 Eclipse 中更改这些设置,而无需摆弄 Tomcat 配置文件。

1. 部署应用程序后,我可以用来浏览某些 servlet/JSP 的 URL 是 localhost:port/Blah/servlet。我想去掉 Blah 前缀。

2. 我想为一些 JSP 文件设置重定向以“隐藏”.jsp 扩展名。例如,我希望 localhost:port/loginlocalhost:port/login.jsp 提供服务,最好不要让浏览器看到 30x 重定向状态代码。

3. 我想设置默认 URL,即 localhost:port/,以重定向到特定的 JSP 或 servlet(同样,最好不发出重定向状态代码)。

任何帮助,包括相关资源的链接,将不胜感激。请注意,如果可能的话,我正在寻找一种在 Eclipse 中配置这些内容的方法。 (如果不可能的话,我想对可怕的 Tomcat XML 文件进行最少的更改。)

I have a web application project in Eclipse that is configured to deploy to a local Tomcat server. Let's call the web application Blah. Here are two questions -- I must be missing something very simple, but I can't find an easy way to change these settings within Eclipse without fiddling with the Tomcat configuration files.

1.
When the application is deployed, the URL I can use to browse to some servlet/JSP is localhost:port/Blah/servlet. I would like to get rid of the Blah prefix.

2.
I would like to set up redirects for some JSP files to "hide" the .jsp extension. For example, I'd like localhost:port/login to be served by localhost:port/login.jsp, preferably without the browser seeing a 30x redirect status code.

3.
I would like to set the default URL, i.e. localhost:port/, to redirect to a particular JSP or servlet (again, preferably without issuing a redirect status code).

Any help, including links to relevant resources, would be greatly appreciated. Please note that I am looking for a way to configure these things from within Eclipse, if possible. (If not possible, I would like to do the minimal amount of changes to the scary Tomcat XML files.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瑶 2025-01-04 10:56:05
  1. 这意味着您需要将应用程序部署为根应用程序。通过将您的战争文件命名为 ROOT.WAR (或展开的战争目录 ROOT),或通过 使用空字符串作为 path 属性为您的 Web 应用程序定义上下文

  2. 那么你不需要重定向,而是转发。或者您只是想将 JSP(这是一个 servlet)映射到给定路径。在 web.xml 文件中定义 servlet 和 servlet 映射,就像定义 servlet 类一样,但使用 而不是 .

  3. 这是使用 web.xml 中的 元素完成的。

  1. This means that you need to deploy your application as the root application. It's easily done by naming your war file ROOT.WAR (or your exploded war directory ROOT), or by defining a context for your web app with an empty string as the path attribute.

  2. Then you don't want a redirect, but a forward. Or you simply want to map the JSP (which IS a servlet) to a given path. Define a servlet and a servlet mapping in the web.xml file, as you would for a servlet class, but use <jsp-file> instead of <servlet-class>.

  3. This is done using the <welcome-file-list> element in the web.xml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文