2015-09-22 17 views
1

我試圖打開我的應用程序的jsp頁面,但出現錯誤。這裏是我的項目結構無法使用Spring MVC在WEB-INF子文件夾中打開jsp

-webapp 
    -WEB-INF 
    -pages 
     -user 
     userHome.jsp 
     userAdministration.jsp 
     index.jsp 

這裏是我的配置類

public class WebAppConfig extends WebMvcConfigurerAdapter { 
... 
public UrlBasedViewResolver setupViewResolver() { 
     UrlBasedViewResolver resolver = new UrlBasedViewResolver(); 
     resolver.setPrefix("WEB-INF/pages/"); 
     resolver.setSuffix(".jsp"); 
... 

的index.jsp是我的開始頁面。

的index.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
... 
<a href="<c:url value="/user" />" role="button">User</a> 

userHome.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
    ... 
<a href="<c:url value="/user/administration" />">Administration</a> 

UserController.java

@Controller 
public class UserController { 
    ... 
@RequestMapping(value = "/user", method = RequestMethod.GET) 
public ModelAndView userArea(Model model) throws Exception { 
    ModelAndView mv = new ModelAndView(); 
    mv.setViewName("user/userHome"); 
    mv.addObject("title", "Home Page"); 
    return mv; 
} 
@RequestMapping(value = "/user/administration", method = RequestMethod.GET) 
    public ModelAndView administration(Model model) throws Exception { 
     ModelAndView mv = new ModelAndView(); 
     mv.setViewName("user/userAdministration"); 
     mv.addObject("title", "Administration"); 
     return mv; 
    } 
... 

USERHOME頁面打開正確的,但是當我點擊鏈接移動到userAdministration我收到以下錯誤

enter image description here

請幫助我打開這個網頁。

+1

嘗試'resolver.setPrefix( 「/ WEB-INF /頁/」);',記斜線在WEB-INF'的'開頭 – Arvind

+0

@Arvind,它的工作!請發佈答案,我會接受它!非常感謝你,我不得不苦苦掙扎。 – olgacosta

回答

0

問題是你在開始丟失了/

resolver.setPrefix("/WEB-INF/pages/");