Note 15 Attempt to locate

If the code is written like this, it means jumping to the page index.jsp 
new ModelAndView(" index.jsp"); 

The so-called view positioning means that the code is still written like this, but it will jump to /WEB-INF/page/index .jsp 
new ModelAndView(" index");

1. Modify springmvc-servlet.xml and add:

1 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
2    <property name="prefix" value="/WEB-INF/page/" />
3    <property name="suffix" value=".jsp" />
4 </bean>

Its role is to assign the view to  the location of /WEB-INF/page/*.jsp

2. Modify IndexController

Put this line of code in the IndexController class:

ModelAndView mav = new ModelAndView("index.jsp");

change into:

ModelAndView mav = new ModelAndView("index");

3. Move index.jsp

Create a new directory page under WEB-INF and
move index.jsp to the WEB-INF/page directory

4. Results

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324674646&siteId=291194637