大家好,又见面了,我是全栈君。
我使用的是SpringMVC框架,做一个小的例子,说明一下对这个内容的学习和理解!
1:我的项目名称为 dufyun_SpringMVC
2:我测试的地址为
代码语言:javascript复制${pageContext.servletContext.contextPath}/testName
3;后台获取的代码为:
代码语言:javascript复制@RequestMapping(value="/testName",method=RequestMethod.GET)
public String testName(Model m ,HttpServletRequest request) throws UnsupportedEncodingException{
System.out.println("request.getServerName()" request.getServerName()); //服务的名称
System.out.println("request.getServerPort()" request.getServerPort());//服务的端口号
System.out.println("request.getLocalName()" request.getLocalName());//本地名称
System.out.println("request.getLocalPort()" request.getLocalPort());//本地端口号
System.out.println("request.getProtocol()" request.getProtocol());//传输协议
System.out.println("request.getRealPath()" request.getRealPath("/"));//获取项目地址
System.out.println("request.getRequstURI()" request.getRequestURI());//获取一个相对的地址
System.out.println("request.getRequstURL()" request.getRequestURL());//获取一个绝对的地址
System.out.println("request.getContextPath()" request.getContextPath());//项目的名称(项目的项目地址)
System.out.println("request.getServletPath()" request.getServletPath());//访问Servle的名称
/*
request.getServerName() localhost
request.getServerPort() 8080
request.getLocalName() 0:0:0:0:0:0:0:1
request.getLocalPort() 8080
request.getProtocol() HTTP/1.1
request.getRealPath() D:KuYuPritaceSSHworkspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsdufyun_SpringMVC
request.getRequstURI() /dufyun_SpringMVC/testName
request.getRequstURL() http://localhost:8080/dufyun_SpringMVC/testName
request.getContextPath() /dufyun_SpringMVC
request.getServletPath() /testName
*/
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/121257.html原文链接:https://javaforall.cn