1

I am creating a web application using Spring Mvc .

I am facing a problem like that when I am not providing value for context-param in web.xml then index page able to display but when i providing value for context-param in web.xml then index page is not displaying .

web.xml :- when not providing value for context-param

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          version="2.5">    

    <display-name>Core Web Application</display-name>

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

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
            <welcome-file>/WEB-INF/pages/index.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        </param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
</web-app>

and when I am trying localhost:8080/CoreWebApp/ I am getting index.jsp

web.xml :- when I providing value for context-param

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          version="2.5">    

    <display-name>Core Web Application</display-name>

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

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
            <welcome-file>/WEB-INF/pages/index.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                    /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
</web-app>

and when I am trying localhost:8080/CoreWebApp/ I am not getting index.jsp.

Please help me to find out the problem.

My Project Structure is as :-
 CoreWebApp
   |_______________ pom.xml
   |
   |_______________ src
   |                 |_____________ main
   |                                 |___________ java
   |                                 |___________ resources
   |                                 |___________ webapp
   |                                                |____ WEB-INF
   |                                                        |_____ applicationContext.xml
   |                                                        |
   |                                                        |_____ mvc-dispatcher-servlet.xml
   |                                                        |
   |                                                        |_____ web.xml
   |                                                        |
   |                                                        |_____ pages
   |                                                                |________ index.jsp
   |
   |______________ target
user2866134
  • 41
  • 1
  • 3

2 Answers2

0

Check the log for some exceptions and add them to the question. Also Spring MVC searches for xml configuration with name: "<the name of the dispatcher servlet>+-servlet" Try to rename applicationContext.xml to mvc-dispatcher-servlet.xml and change the path and accordingly.

Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
  • Hey Evgeni, This is not the problem of **mvc-dispatcher-servlet.xml** . Due to **Spring Mvc** convention , spring framework look for **-servlet.xml**. In my **web.xml** ,At **** , servlet-name is "**mvc-dispatcher**" and i have **mvc-dispatcher-sevlet.xml** under "**WEB-INF**" folder – user2866134 Jan 04 '14 at 13:33
  • OK. Any exceptions in the log? – Evgeni Dimitrov Jan 04 '14 at 16:29
0

Your spring Servlet has a mapping for "/" And that the path for the index page.

farvilain
  • 2,552
  • 2
  • 13
  • 24