javaWeb学习—getRequestURI,getRequestURL等的学习

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
	*/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/121257.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • android之Unable to execute dex: Multiple dex files define「建议收藏」

    出现了异常Dex Loader:Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; 查了好多方法都不行,最后得到了解决方法:

    2022年3月11日
    38
  • AC自己主动机 总结

    AC自己主动机 总结

    2022年1月1日
    46
  • 零基础学Java(13)方法参数[通俗易懂]

    零基础学Java(13)方法参数[通俗易懂]前言首先回顾一下在程序设计语言中关于如何将参数传递给方法的一些专业术语。按值调用表示方法接收的是调用者提供的值。而按引调用表示方法接收的是调用者提供的变量地址。方法可以修改按引用传递的变量的值,而不

    2022年8月7日
    11
  • 统计学 入门基础PDF( Probability Density Function) 和PMF ( Probability Mass Function )

    统计学 入门基础PDF( Probability Density Function) 和PMF ( Probability Mass Function )PMF(概率质量函数):是对 离散随机变量的定义. 是离散随机变量 在各个特定取值的概率. 该函数通俗来说,就是对于一个离散型概率事件来说,使用这个函数来求它的各个成功事件结果的概率.PDF(概率密度函数):是对连续性随机变量的定义.与PMF不同的是PDF在特定点上的值并不是该点的概率,连续随机概率事件只能求一段区域内发生事件的概率,通过对这段区间进

    2022年5月23日
    47
  • 集合遍历python_Python 集合遍历

    集合遍历python_Python 集合遍历1 set 集合可变集合 set 可添加和删除元素 非可哈希的 不能用作字典的键 也不能做其他集合的元素不可变集合 frozenset 与上面恰恰相反 Paste Image png 创建集合 gt gt gt s set beginman gt gt gt sset a b e g i m n gt gt gt t fr

    2025年12月14日
    2
  • python调用c++动态库_python登陆mt4

    python调用c++动态库_python登陆mt4广告关闭腾讯云11.11云上盛惠,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元!运行平台:windowspython版本:python3.6ide:sublimetext其他工具:chrome浏览器0、写在前面的话本文是基于基础版上做的修改,如果没有阅读基础版,请移步python爬虫抓取智联招聘(基础版)在基础版中,构造url时使用了urllib…

    2022年8月15日
    10

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号