分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

HttpServletRequest获取请求路径

发布时间:2023-09-06 02:30责任编辑:彭小芳关键词:暂无标签

 

Java代码  
  1. HttpServletRequest获取请求路径  
  2. 1、        //Returns the part of this request‘s URL from the protocol name up to the query string in the first line of the HTTP request  
  3.         //  eg.  /ser.do?method=add_pre&type=mad  
  4.         String url = request.getRequestURI();    
  5.     return /ssm/ser.do  
  6. 2、        //The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters  
  7.           //eg.      http://localhost:8080/ssm/ser.do?method=add_pre&type=mad  
  8.         StringBuffer url_buffer = request.getRequestURL();  
  9.     return http://localhost:8080/ssm/ser.do  


HttpServletRequest 的这两种方法都只能得到不包含参数的请求url,区别如下: 

1 前者返回相对路径,后者返回完整路径 

2 前者返回string ,后者返回stringbuffer 

要想得到完整请求url可以通过如下方法,getQueryString()得到的是url后面的参数串,和前者相加就是带参数的请求路径了 
Java代码  
  1.     String queryString = request.getQueryString();  
  2. String fullPath = url + queryString;     
  3. // 或者是url_buffer.toString()+queryString;  
  4. 即 /ssm/ser.do + method=add_pre&type=mad  
???????????

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

HttpServletRequest获取请求路径

原文地址:https://www.cnblogs.com/sjwudhwhhw/p/10298227.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved