Web应用程序URL访问java

发布于 2024-12-11 12:40:37 字数 963 浏览 0 评论 0原文

我试图了解这些请求是如何工作的。不幸的是,我首先被困在编码上,然后才被困在理解上。

几年前,我用 java 编写了一些非常基本的 Web 应用程序,它确实按预期工作。在其主网页(.jsp)上,我将以下内容作为菜单按钮之一:

<p><a href="home.jsp">test</a></p>

我目前正在编写新的网络应用程序,但忘记了很多。这次我用 Spring MVC 正确地完成了它。我真的无法理解为什么这个片段不再将我带到当前 Web 应用程序中的 home.jsp 以及为什么一开始我确实在旧应用程序中使用它。

Apache给出:请求的资源()不可用。

这并不是说我需要那种直接交互,只是我想了解资源是否可以通过 URL 访问? Spring MVC 是否给我带来了额外的安全性,只有 servlet 处理的请求才能产生视图?我是否错过了一些非常微不足道的事情?

此外,在同一个旧的 Web 应用程序菜单中,我可以直接链接到 Servlet,但目前我无法在新的 Web 应用程序中直接引用 Servlet。我可以发出相关请求,该请求将由 servlet 捕获,但不能通过其名称捕获。

Apache给出:请求的资源()不可用。

从菜单中引用 servlet:

<% if((String) session.getAttribute("passengerFound") != null){ %>
<a href="TripRecentBook"><img style="border:0" src="menuButtons/My Trips.png" alt="My Trips"/></a> <%} %>

谢谢,我敢打赌这真的很简单。我真的很想明白,请帮忙。 我知道它与前端控制器(dispatcherServlet)有关,但我无法在脑海中形成逻辑且坚定的解释。

I am trying to understand how the requests works. Unfortunately I was thrown at coding first and only then at understanding.

I wrote some really basic webapplication in java few years ago and it did work as expected. On its main web-page(.jsp) I had following as one of the menu buttons:

<p><a href="home.jsp">test</a></p>

I am currently writing new webapp and forgot a lot. This time I am doing it with Spring MVC and properly. I can't really understand why this snippet no longer brings me to the home.jsp in current webapplication and why at first I did use it in old app.

Apache gives: The requested resource () is not available.

It is not that I need that sort of direct interaction, it is just I am trying to understand whether resources are accessible via URL? Does Spring MVC brings me extra security, where only servlet handled requests can result in a view? Am I missing something really trivial?

Moreover in that same old web app menu I had direct link to the servlet, but currently I can't make such direct reference to the servlet in the new webapp. I can make relevant request which will be captured by the servlet, but not by the name of it.

Apache gives: The requested resource () is not available.

Reference to servlet from menu:

<% if((String) session.getAttribute("passengerFound") != null){ %>
<a href="TripRecentBook"><img style="border:0" src="menuButtons/My Trips.png" alt="My Trips"/></a> <%} %>

Thanks, I bet it is really simple. I really want to understand, please help.
I know that it has something to do with Front Controller(dispatcherServlet), but I can't form logical and firm explanation in my head.

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

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

发布评论

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

评论(2

萌梦深 2024-12-18 12:40:37

这只是我想了解资源是否可访问
通过网址

简而言之,不。使用 Spring MVC 时的默认行为和推荐配置是将 Spring DispatcherServlet 映射到 / url 模式,这意味着所有请求都发送到 DispatcherServlet。开箱即用的调度程序 servlet 不会为任何静态资源请求提供服务。如果需要,两个主要选项是

  1. 将 DispatcherServlet 映射到 root 之外的另一种模式,有效地将 Spring MVC 部分隔离到子上下文
  2. 将资源映射添加到您的 spring 上下文(您的 applicationContext.xml)。

上面的内容将告诉 spring mvc 将所有对 /res/** 的请求视为对静态资源(如图像等),并且这些资源物理上位于应用程序根目录的 /res/ 文件夹中。

it is just I am trying to understand whether resources are accessible
via URL

In short, no. The default behavior and recommended configuration when using Spring MVC is to map the Spring DispatcherServlet to the / url pattern, meaning ALL requests are sent to the DispatcherServlet. Out of the box, the dispatcher-servlet will NOT service any requests for static resources. If this is desired, the two main options are

  1. Map the DispatcherServlet to another pattern than root, effectivly isolating the Spring MVC portion to a sub-context
  2. Add a resource-mapping to your spring context (your applicationContext.xml).

<mvc:resources mapping="/res/**" location="/res/" />

This above would tell spring mvc to treat all request to /res/** as requests for static resources (like images etc) and that those resources are physically located in the /res/ folder in the application root.

过期以后 2024-12-18 12:40:37

您可能只是缺少一个“/”,如 "/home.jsp" 而不是 "home.jsp"

You might just be missing a "/" as in "/home.jsp" instead of "home.jsp"

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