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


相关推荐

  • isnotempty和isnotnull_was not iterable

    isnotempty和isnotnull_was not iterable先看看isEmpty和isBlank  从效果来看,当a=””,字符中有空格时,IsEmpty是算他不为空的本质上讲:isEmpty等价于str==null||str.length==0isBlank等价于str==null||str.length==0||str.trim().length==0我们再来看非空:is…

    2022年10月7日
    2
  • java hd seks_jodconverter-web/src/main/java/cn/keking/service/impl/AseKsReportServiceImpl.java · mes…

    java hd seks_jodconverter-web/src/main/java/cn/keking/service/impl/AseKsReportServiceImpl.java · mes…packagecn.keking.service.impl;importcn.keking.hutool.StrUtil;importcn.keking.render.AseKsTableRenderPolicy;importcn.keking.render.CustomReplaceOptionalTextPictureRefRenderPolicy;importcn.keking.s…

    2022年7月7日
    31
  • VMWare虚拟机上网的方法

    VMWare虚拟机上网的方法VMWare虚拟机上网的方法1推荐局域网方式:如果主机是在局域网内通过网关或代理上网,那虚拟机的网络方式设为Bridged连接,把IP地址设为同主机在一个网段,比如主机IP是192.168.0.45,网关是192.168.0.1,那虚拟机的IP设为192.168.0.2-254中的一个,注意不要和已有的IP重复,然后网关也设为192.168.0.1,就可以上网了。宽带拨号方式

    2022年5月19日
    45
  • Linux查看系统基本信息,版本信息(最全版)

    Linux查看系统基本信息,版本信息(最全版)Linux下如何查看版本信息,包括位数、版本信息以及CPU内核信息、CPU具体型号1.uname-a  (Linux查看版本当前操作系统内核信息)2.cat/proc/version(Linux查看当前操作系统版本信息)3.cat/etc/issue 或cat/etc/redhat-release(Linux查看版本当前操作系统发行版信息)4.cat/…

    2022年6月6日
    164
  • TCP连接异常终止(RST包)场景分析

    TCP连接异常终止(RST包)场景分析一、TCP异常终止(reset报文)TCP的异常终止是相对于正常释放TCP连接的过程而言的,我们都知道,TCP连接的建立是通过三次握手完成的,而TCP正常释放连接是通过四次挥手来完成。但是有些情况下,TCP在交互的过程中会出现一些意想不到的情况,导致TCP无法按照正常的三次握手建立连接或四次挥手来释放连接。如果此时不通过其他的方式来释放TCP连接的话,这个TCP连接将会一直存在,占用系统的资源。在这种情况下,我们就需要有一种能够释放TCP连接的机制,这种机制就是TCP的reset报文。reset报文是指

    2022年10月1日
    3
  • JVM成神之路-类加载机制-双亲委派,破坏双亲委派

    概述概念虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验、转换解析和初始化,最终形成可以被虚拟机直接时候用的Java类型。类的生命周期类从被加载到虚拟机内存中开始,到卸载出内存为止,它的整个生命周期包括:加载、验证、准备、解析、初始化、使用、卸载。其中验证、准备、解析统称为连接上图中,加载、验证、准备、初始化和卸载这5个阶段的顺序是确定的,类的加载过程必须严…

    2022年4月16日
    36

发表回复

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

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