0

I have the following folder structure for my Maven WebApp Project

src
 +-----main
        +-----java
        |       +-----com
        |               +------controller
        |                          +-----HomeController.java
        |
        +-----resources
        +-----webapp
                 +-----resources
                 |          +-----css
                 |                 +-----home.css
                 +-----WEB-INF
                         +-----jsp
                         |      +------home.jsp
                         +-----eLibrary-servlet.xml
                         +-----web.xml

web.xml:

<servlet>
    <servlet-name>eLibrary</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>eLibrary</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<display-name>eLibrary</display-name>

eLibrary-servlet.xml:

<mvc:annotation-driven />

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

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

HomeController.java:

@Controller
    public class HomeController {
        @RequestMapping("/")
        public String getHomePage() {
            return "home";
        }
    }

And in my home.jsp, I'm trying to access the CSS file using ${pageContext.request.contextPath}/resources/css/home.css

But neither my JSP file(i.e. home.jsp) nor the CSS file(i.e. home.css) is loading in browser and I'm getting HTTP Status 404 when accssing http://localhost:8080/eLibrary/ with a message

/eLibrary/WEF-INF/jsp/home.jsp

and description

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

3
  • Are you using spring boot ? Commented Sep 18, 2018 at 4:06
  • Spring Boot-No. I got the error. There's a typo in my eLibrary-servlet.jsp Commented Sep 18, 2018 at 4:09
  • I got the error. There's a typo in my eLibrary-servlet.jsp - In that case close this question Commented Sep 18, 2018 at 4:16

3 Answers 3

1

You have a type, in here /WEF-INF/jsp/

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

change it to /WEB-INF/jsp/

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>
Sign up to request clarification or add additional context in comments.

Comments

0

There is a mistake in Configuring the Spring DispatcherServlet. You need to mention your eLibrary-servlet.xml in web.xml. Need to rearrange the web.xml as mentioned in the below link.

https://docs.spring.io/spring-flex/docs/1.0.x/reference/html/ch02s02.html

<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/eLibrary-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

Hope this is usefull.

Comments

0

You have a typo error in your elibrary-servlet.xml

<mvc:annotation-driven />

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

<mvc:resources location="/resources/" mapping="/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.