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 
0

2 Answers 2

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.

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

2 Comments

Hey Evgeni, This is not the problem of mvc-dispatcher-servlet.xml . Due to Spring Mvc convention , spring framework look for <servlet-name>-servlet.xml. In my web.xml ,At <servlet-mapping> , servlet-name is "mvc-dispatcher" and i have mvc-dispatcher-sevlet.xml under "WEB-INF" folder
OK. Any exceptions in the log?
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.