【问题标题】:Spring not loading CSS and js with Spring SecuritySpring 不使用 Spring Security 加载 CSS 和 js
【发布时间】:2016-12-09 01:35:39
【问题描述】:

我是 Spring MVC 的新手。我创建了一个包含样式和客户端验证的登录页面。项目部署后,我看到登录页面没有任何样式和验证。我该如何解决这个问题?我已经提供了我的项目结构、部署描述符和 spring 配置文件。

我对 img、css、js 等静态内容使用 <mvc:resources> 配置

Project Structure

网页 .xml

<servlet>
    <servlet-name>spring-config</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring-config</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/application-context*.xml</param-value>
</context-param>

`

spring-config-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="org.fms"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/Resources**" location="/Resources/"/>


<!--View Resolver Configuration-->

<bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="order" value="1"/>
    <property name="basename" value="view"/>
</bean>
<bean id="viewResolver2"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="order" value="2"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

application-context.xml
Application Context

【问题讨论】:

  • 你能展示一下你是如何在 jsp 文件中包含 css、js 引用的吗?
  • 如果 mvc:resources 映射是 "/Resources/**" 那么你应该包含 css,js 文件作为 "> 在 jsp 中
  • "> ">

标签: spring spring-mvc spring-security


【解决方案1】:

谢谢斯里坎特

问题在于资源文件夹结构。我已将资源文件夹重组为

资源
--css
--js
--图片

在此更改后,我的页面正确加载。

【讨论】:

    猜你喜欢
    • 2014-10-11
    • 2018-03-24
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多