0

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/**"/>

Project Folder enter image description here

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.

1
  • From Spring 3.1, you can use - <mvc:default-servlet-handler /> Commented Sep 17, 2016 at 20:19

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

why resources must go directly under webapp? is there any way to customize its location?
1

Your resource mapping is wrong. Should be:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.