Question

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.

Was it helpful?

Solution

<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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top