【问题标题】:I have added css folder directly in web content and i have mapped in spring.xml. But css is not loading我已经直接在 web 内容中添加了 css 文件夹,并且我已经在 spring.xml 中进行了映射。但是css没有加载
【发布时间】:2017-07-16 15:27:12
【问题描述】:

`

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">  

    <context:component-scan  base-package="com.homebanking" /> 
    <mvc:annotation-driven/> 
    <context:annotation-config />
    <mvc:resources location="/css/*" mapping="/css/*"/>
    <mvc:resources location="/js/*" mapping="/js/*"/> 


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

    <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/homebanking" />
        <property name="username" value="root" />
        <property name="password" value="root" />
    </bean>

     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="com.homebanking.model"/>       
        <property name="hibernateProperties">
            <props>
                <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
    </bean>  
</beans> 

`

我已经使用 mvc:resource 标签在 spring-servlet.xml 文件中映射了 css 文件。但是css没有加载。我已将 css 文件夹放在网页内容中

 <mvc:resources location="/css/*" mapping="/css/*"/>
<mvc:resources location="/js/*" mapping="/js/*"/> 

请帮帮我。它以前工作得很好。但突然 css 没有加载。

【问题讨论】:

  • 你能告诉我你的文件夹结构和你的xml文件吗
  • 我无法添加我的文件夹结构的图片
  • 我已将 css 文件夹直接放在 webcontent 文件夹下
  • 我已经添加了我的 spring .xml 文件

标签: java spring-mvc


【解决方案1】:

如果您将 css 文件夹放在 webcontent 下,您需要像这样指定您的资源:

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

然后你可以像这样导入你的css文件:

<link href="<c:url value="/css/youMain.css" />" rel="stylesheet">

【讨论】:

  • 我按照你说的做了改变..现在它正在工作..非常感谢:)
【解决方案2】:

你需要写链接这个&lt;resources mapping="/resources/**" location="/resources/" /&gt; 有关更多信息,您可以参考下面的 stackoverflow 链接以获得正确的参考:

https://stackoverflow.com/a/32157609/7801800 by AshOne

【讨论】:

    猜你喜欢
    • 2018-02-21
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    相关资源
    最近更新 更多