在我的 maven Spring 项目中,netbeans CSS/Js 文件未打开.. web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>OrderManager</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>SpringConfiguration</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringConfiguration</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
SpringConfiguration-servlet.xml
e<?xml version="1.0" encoding="UTF-8"?><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"
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">
<context:component-scan base-package="com.ordermanager.users.controller" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/**"/>
即使 Controller 和其他功能正常工作,我也无法访问任何 css 或 JS 文件。 但如果我在浏览器中打开以下网址 http://localhost:8080/OrderManager/resources/css/loginpagestyle.css ,显示未找到 404。
最佳答案
经过多次搜索,通过删除位置设置值中的初始“/”解决了我的 404 问题。所以而不是
<mvc:resources mapping="/resources/**" location="/resources/"/>
与之前的答案一样,我使用了:
<mvc:resources mapping="/resources/**" location="resources/"/>
虽然变化不大,但确实起到了作用。我假设“/”向路径添加了额外的文件夹级别。另外,我将 resources 文件夹直接放在 webapp 文件夹下。
感谢Suda's Tech Zone感谢您帮助我解决这个问题。
使用Maven 4.0.0、eclispse kelper、java 1.7、mybatis 3.1.1。
关于java - Spring MVC CSS/JS 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39545838/