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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • docker 连接外部数据库_SpringBootVFS

    docker 连接外部数据库_SpringBootVFSSpringBoot-MYSQL数据库连接

    2025年5月27日
    3
  • heapdump.phd分析工具_dump文件分析工具

    heapdump.phd分析工具_dump文件分析工具heapdump分析工具是一款强大的数据分析工具,它可以用图表的形式来展现相应的分析结果,在使用heapdump分析工具之前请先安装JDK1.6。运行环境1.运行环境要求JDK1.6或以上如果JDK版本过低,报错如下:Exceptioninthread”main”java.lang.NoClassDefFoundError:java/util/regex/PatternSyntaxEx…

    2022年10月2日
    3
  • NestedScrollView+Viewpager+Recycleview的滑动冲突

    NestedScrollView+Viewpager+Recycleview的滑动冲突最新业务需求变化 一个页面多个 Recycleview Viewpager viewpager 实现左右滑动 且可以手动滑动 页面逻辑简单 就是数据比较大 最初的时候实现有滑动冲突 后边使用 NestedScroll 可以实现滑动 但是 Viewpager 不能实现手动滑动 Recycleview 的 item 事件冲突 这个只在华为 7 0 手机上出现 华为 8 0 及三星手机上未发现问题 网上也是各种找 后边看

    2025年7月3日
    2
  • FIONREAD 判断 socket有多少数据可读[通俗易懂]

    FIONREAD 判断 socket有多少数据可读[通俗易懂]Ioctl(sockfd,FIONREAD,&npend); /*checkFIONREADsupport*/检查sockfd表示的文件描述符中有多少数据可以读取

    2022年7月23日
    16
  • mysql的mediumtext类型字段在java如何获取

    mysql的mediumtext类型字段在java如何获取数据库:PO:重点是autoResultMap=true和@TableField(typeHandler=FastjsonTypeHandler.class)@Data@EqualsAndHashCode(callSuper=false)@TableName(value=”xxx”,autoResultMap=true)@ApiModel(“一分钱充值用户配置表”)publicclassxxximplementsSerializable{@Tabl

    2022年5月18日
    56
  • hadoop hdfs命令_hadooplinux命令

    hadoop hdfs命令_hadooplinux命令概述所有的HDFS命令都调用bin/hdfs脚本文件,如果运行hdfs脚本没有带任何参数的话,则打印所有命令的描述。 使用:hdfs[SHELL_OPTIONS]COMMAND[GENERIC_OPTIONS][COMMAND_OPTIONS]Hadoop是一个参数解析框架,采用解析泛型选项以及运行类。命令参数 描述 –config–loglevel …

    2022年10月4日
    3

发表回复

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

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