简体   繁体   中英

Spring MVC - what is url path info?

I would like to know what is a url path info?

For example in

http://myserver:8080/servletname/handlermethod

Is it the whole path including server name:

http://myserver:8080/servletname/handlermethod

or is it just

/servletname/handlermethod

getPathInfo() according to the doc:

Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character.

so in your example it will return /handlermethod

If you want to have /servletname/handlermethod you should use getRequestURI() .

getRequestURL() will return the full URL made by the client (except string parameters).

The path info in Spring MVC may imply for the info sent via a URL. In a Spring MVC Controller you can easily set a request mapping which include a variable value place holder which is bound to an argument with @PathVariable annotation in the method signature - related to the request mapping. For eaxmple:

  @RequestMapping(value = "/user/{userId}")  
public ModelAndView getUserByPathVariable(@PathVariable Long userId, HttpServletRequest request,  HttpServletResponse response) { 
        System.out.println("Got request param: " + userId);

You take a look here for a more detailed example: Spring MVC Controller Example

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