简体   繁体   中英

Why i get 404 error trying to acess a rest?

im getting 404 error when i try to visit an url like:

GET: /test/{id}

PS.: id is a string that changes according users filter

I have "/test" already mapped in web.xml, but i dont know how to declare some value that "i dont know", in this case, "id".

Let me show an example:

@RequestMapping(value="/test/{id}", method = RequestMethod.GET) 
public ModelAndView testingId(@PathVariable String id ){

    System.out.println("id");

    return new ModelAndView("returns", "returns", id);
}

Any Help?

What method are you using to configure your web application DispatcherServlet (web.xml or WebApplicationInitializer)

Your request needs to include the servlet context , servlet mapping and resource mapping. Assuming that your application is called sample.war and your DispatcherServlet is mapped to /app/* then your request should be

GET : /sample/app/test/4

  • you are returning ModelAndView, what is you ViewResolver? By default it will try to find jsp with that name and it can't find it. Do you want to return jsp or json object?
  • Does your application use SpringBoot or did you configured it with @AutoScan or configured Controller mapping?
  • Put a debug statement and make sure that your request gets into the method, debug into spring methods and you can see how Spring resolves the view.
  • Id would be identifier of the resource you are trying to query. Example: /users/123456 - user id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM