Why does my web page expire?

Why don't I see the home page in the browser in the following Spring web app?

  • Here is the controller that I use @Controller public class ProjectController { @Autowired private ProjectService ProjectService; @Autowired public ProjectController(ProjectService ProjectService){ this.ProjectService = ProjectService; } @RequestMapping({"/","/find"}) public String getPersonList(@RequestParam("regNo") String regNo, ModelMap model) { model.addAttribute("ProjectList", ProjectService.getStudentProject(regNo)); return "find"; } } I have a page called find.jsp under WEB-INF/jsp folder. But when I hit localhost:8080/find I get HTTP status 400 error Following is my dispatcher-servlet.xml where I have made the mappings <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="Index of /schema/beans" xmlns:xsi="Page on w3.org" xmlns:context="Index of /schema/context" xmlns:p="Page on springframework.org" xmlns:mvc="Index of /schema/mvc" xmlns:beans="Index of /beans" xsi:schemaLocation="Page on springframework.org Page on springframework.org Page on springframework.org Page on springframework.org"> <mvc:annotation-driven/> <context:component-scan base-package="com.MyAppName.www" /> <!-- Factory bean that creates the Mongo instance --> <bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean"> <property name="host" value="localhost" /> </bean> <!-- MongoTemplate for connecting and quering the documents in the database --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongo" ref="mongo" /> <constructor-arg name="databaseName" value="MyApp" /> </bean> <!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes --> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp" p:suffix=".jsp" /> </beans> This is how web.xml looks <web-app xmlns="Java EE: XML Schemas for Java EE Deployment Descriptors" xmlns:xsi="Page on w3.org" xsi:schemaLocation="Java EE: XML Schemas for Java EE Deployment Descriptors Page on sun.com" version="2.5"> <display-name>Spring With MongoDB Web Application</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>/WEB-INF/find.jsp</welcome-file> </welcome-file-list> </web-app> [/code/ This is how my server log looks like. I am using Tomcat 7.0 [code] The url I use is localhost:8080/find.jsp and I get 404 error. [/code]

  • Answer:

    Following were the issues and corresponding solutions 1) The project doesn't have webapp folder. When you create a project using maven be mindful. You can follow the steps mentioned here http://blog.manishchhabra.com/2013/04/spring-data-mongodb-example-with-spring-mvc-3-2/ 2) Make sure you have the jsp files inside theWEB-INF folder and the path is properly mentioned all across the application. I got several other errors in between, but all those could be solved if you search in google and select the first stackoverflow result.

Anonymous at Quora Visit the source

Was this solution helpful to you?

Other answers

Here's what I gather from the code snippets. When the URL : http://localhost:8080/find.jsp is hit, 1. DispatcherServlet transfers control to the Controller class. 2. The getPersonList() method in the Controller has a @RequestMapping that can handle "/find". The resultant JSP as per "jspViewResolver" will be /WEB-INF/jsp/find.jsp. But I guess the URL that you should hit for this flow to occur would be : http://localhost:8080/ctxRoot/find.jsp, where "ctxRoot" is the Context root of your Project (Refer Section 6 http://www.baeldung.com/spring-requestmapping) . By Context root, I mean the one present in : Project Properties -> Web Project Settings -> "Context root:" Let me know if the URL change helps. Thanks for the A2A.

Radhikaa Bhaskaran

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.