春季MVC瓷砖 - 不拾取资源文件夹

发布于 2024-12-04 11:54:09 字数 1642 浏览 0 评论 0原文

我需要更改 Spring Servlet 的映射以指向 /sample 与 /sample.html。

我将 url 模式更改为以下内容。 urlPattern

        <url-pattern>*.html</url-pattern>



<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

进行此更改后,文件夹中的任何样式表引用都不会被拾取。我认为这是因为 DispatcherServlet 试图读取此内容。当我对 servlet-context.xml 文件尝试以下操作时,没有任何效果。

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.ResourceBundleViewResolver"
    p:basename="views" />

<context:component-scan base-package="*****" />


<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
    p:definitions="/WEB-INF/tiles-defs.xml" />


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

我想也许我需要添加另一个视图解析器,但这没有任何区别。

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

任何帮助将不胜感激。似乎无论我做什么,我都会收到 404 错误。

I need to change mapping for my spring servlet to point to /sample vs. /sample.html.

I made a change in the url pattern to the following. The urlPattern is

        <url-pattern>*.html</url-pattern>



<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Once this change is made, none of the style sheets reference in a folder are picking up. I thought this was because DispatcherServlet was trying to read this. When I try the following to my servlet-context.xml file, NOTHING works.

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.ResourceBundleViewResolver"
    p:basename="views" />

<context:component-scan base-package="*****" />


<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
    p:definitions="/WEB-INF/tiles-defs.xml" />


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

I thought maybe I needed to add another view resolver, but that doesn't make any difference.

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

Any help would be greatly appreciated. It seems no matter what I do I get a 404 Error.

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

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

发布评论

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

评论(1

幸福不弃 2024-12-11 11:54:09

资源是通过 Spring 调度程序访问的。因此,您需要确保将请求委托给 web.xml 中的 spring 调度程序 sevlet。

您必须将所有请求委托给调度程序,不仅是 html,还包括 css、图像……

The resourses are accessed througt the spring dispatcher. So you need to make sure that the requests are delegated to the spring dispatcher sevlet in the web.xml.

You must delegate all requests to the dispatcher, not only html, but also css, images,...

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