2013-11-20 140 views
0

如何修復404錯誤,請求的資源不可用。從調度員servlet.xml中Spring RequestMapping 404錯誤?

的ViewResolver

<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    p:prefix="/WEB-INF/" p:suffix=".jsp"> 
</bean> 



@RequestMapping("/Locations/edit/{locationId}") 
public void edit(@PathVariable String locationId,ModelMap map) { 
    Locations location=new Locations(); 
    location=locationsService.getByID(Integer.parseInt(locationId)); 
    map.put("location", location);  
} 

錯誤 HTTP狀態404 - /DoctorsBeta/WEB-INF/Locations/edit/1.jsp 描述所請求的資源不可用。

回答

2
<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    p:prefix="/WEB-INF/jsps/" p:suffix=".jsp"> 
</bean> 





@RequestMapping("/Locations/edit/{locationId}") 
    public String edit(@PathVariable String locationId,ModelMap map) { 
     Locations location=new Locations(); 
     location=locationsService.getByID(Integer.parseInt(locationId)); 
     map.put("location", location); 
     reutrn "nameOfYourJspFileHere"; 
    } 

編輯我只是想出你的JSP名稱是不是1,它是ID,所以當你發送/位置/編輯/ 1

請注意,所有的JSP應該駐留在/ WEB -INF /(但我建議添加一些其他文件夾(jsps,視圖或表明jsp文件在那裏)dir,所以當你返回視圖名稱時它會附加前綴和後綴,所以jsps文件夾可以有子文件夾,所以每次你返回視圖名稱確保它在正確的路徑 例如,視圖名稱= index.jsp(/WEB-INF/jsps/common/index.jsp)所以在你的方法,你會返回"common/index" 希望它可以幫助。

0

太虛方法不返回任何JSP頁面,要麼你應該返回一個字符串(「jsp中的名稱」)或頁面

@RequestMapping("/Locations/edit/{locationId}") 
    public String edit(@PathVariable String locationId,ModelMap map) { 
     Locations location=new Locations(); 
     location=locationsService.getByID(Integer.parseInt(locationId)); 
     map.put("location", location); 
     return "test"; 
    } 

的ModelAndView中是否會映射這樣

<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    p:prefix="/WEB-INF/jsps/" 
    // test 
    p:suffix=".jsp"> 
</bean> 

它將搜索/WEB-INF/jsps/test.jsp