Reputation: 587
In my maven Spring Project in netbeans CSS/Js file not opening .. 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/**"/>
i cant able access any css or JS file even after controller and other function working fine .. but if i open the following url in browser http://localhost:8080/OrderManager/resources/css/loginpagestyle.css, it's showing not 404 found.
Upvotes: 0
Views: 5234
Reputation: 41
After much search, my 404 issue was resolved by removing the initial "/" in the location setting value. So instead of
<mvc:resources mapping="/resources/**" location="/resources/"/>
as in the previous answer, I used:
<mvc:resources mapping="/resources/**" location="resources/"/>
Small change, but it did the trick. I'm assuming the "/" added an additional folder level to the path. Also, I placed the resources folder directly under the webapp folder.
Thank you to Suda's Tech Zone for helping me with this issue.
Using Maven 4.0.0, eclispse kelper, java 1.7, mybatis 3.1.1.
Upvotes: 2
Reputation: 17731
Your resource mapping is wrong. Should be:
<mvc:resources mapping="/resources/**" location="/resources/"/>
Upvotes: 1