문제

How to fix 404 error ,The requested resource is not available.

viewResolver from dispatcher-servlet.xml

<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);      
}

error HTTP Status 404 - /DoctorsBeta/WEB-INF/Locations/edit/1.jsp description The requested resource is not available.

도움이 되었습니까?

해결책

<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";
    }

EDIT I just figured that your jsp name is not 1 and it is id, so when you send /Locations/edit/1

Note that all of your jsps should reside in /WEB-INF/ (but i suggest add some other folder (jsps,views or something that indicates that jsp files are there) dir, so when you return view name it will append prefix and suffix. So jsps folder can have subfolders, so every time you return view name make sure it is in correct path. e.g. view name = index.jsp(/WEB-INF/jsps/common/index.jsp) so in your method you would return "common/index" Hope it helps.

다른 팁

Void method does not return to any jsp page, Either you should return a string("name of the jsp") or the ModelAndView of the page

@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";
    }

If It will map like this

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

It will search for /WEB-INF/jsps/test.jsp

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top