javaWeb学习—getRequestURI,getRequestURL等的学习

我使用的是SpringMVC框架,做一个小的例子,说明一下对这个内容的学习和理解!

1:我的项目名称为 dufyun_SpringMVC 

2:我测试的地址为

${pageContext.servletContext.contextPath}/testName

3;后台获取的代码为:

@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:\KuYuPritace\SSH\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\dufyun_SpringMVC\
	request.getRequstURI()	/dufyun_SpringMVC/testName
	request.getRequstURL()	http://localhost:8080/dufyun_SpringMVC/testName
	request.getContextPath()	/dufyun_SpringMVC
	request.getServletPath()	/testName
	*/


你可能感兴趣的:(javaweb)