简体   繁体   English

Spring MVC-什么是网址路径信息?

[英]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 http:// myserver:8080 / servletname / handlermethod

Is it the whole path including server name: 是包括服务器名称的整个路径:

http://myserver:8080/servletname/handlermethod http:// myserver:8080 / servletname / handlermethod

or is it just 还是只是

/servletname/handlermethod / servletname / handler方法

getPathInfo() according to the doc: 根据文档获取getPathInfo()

Returns any extra path information associated with the URL the client sent when it made this request. 返回与客户端发出此请求时发送的URL关联的任何其他路径信息。 The extra path information follows the servlet path but precedes the query string and will start with a "/" character. 额外的路径信息在servlet路径之后,但在查询字符串之前,并以“ /”字符开头。

so in your example it will return /handlermethod 因此在您的示例中它将返回/handlermethod

If you want to have /servletname/handlermethod you should use getRequestURI() . 如果要使用/servletname/handlermethod ,则应使用getRequestURI()

getRequestURL() will return the full URL made by the client (except string parameters). getRequestURL()将返回客户端创建的完整URL(字符串参数除外)。

The path info in Spring MVC may imply for the info sent via a URL. Spring MVC中的路径信息可能暗示通过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. 在Spring MVC Controller中,您可以轻松地设置一个请求映射,其中包括一个变量值占位符,该变量值占位符绑定到方法签名中带有@PathVariable批注的自变量-与请求映射有关。 For eaxmple: 对于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 您可以在此处查看更详细的示例: Spring MVC Controller示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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