/**
* 演示Request对象获取请求行数据
*/
@WebServlet("/test")
public class RequestDemo1 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//一、获取请求行
//1.获取请求方式:GET
String method = request.getMethod();
System.out.println(method);
//2.(*)获取虚拟目录:/request
String contextPath = request.getContextPath();
System.out.println(contextPath);
//3.获取Servlet路径:/demo
String servletPath = request.getServletPath();
System.out.println(servletPath);
//4.获取get方式请求参数:name=zhangshan
String queryString = request.getQueryString();
System.out.println(queryString);
//5.(*)获取请求URI:/request/demo
//* String getRequestURI(): /request/demo
String requestURI = request.getRequestURI();
System.out.println(requestURI);
//* StringBuffer getRequestURI():http://localhost/request/demo
StringBuffer requestURL = request.getRequestURL();
System.out.println(requestURL);
//6.获取协议及版本:HTTP/1.1
String protocol = request.getProtocol();
System.out.println(protocol);
//7.获取客户机的IP地址:
//*String getRemoteAddr()
String remoteUser = request.getRemoteUser();
System.out.println(remoteUser);
}
}

入门servlet:request获取请求行数据的更多相关文章

  1. 入门servlet:request获取请求头数据

    @WebServlet("/RequestDemo2") public class RequestDemo2 extends HttpServlet { protected voi ...

  2. 入门servlet:request获取请求体数据

    @WebServlet("/RequestDemo5") public class RequestDemo5 extends HttpServlet { protected voi ...

  3. Response ServletContext 中文乱码 Request 编码 请求行 共享数据 转发重定向

    Day35  Response 1.1.1 ServletContext概念 u 项目的管理者(上下文对象),服务器启动时,会为每一个项目创建一个对应的ServletContext对象. 1.1.2  ...

  4. 03-【request对象获取请求的数据 & request对象存取值】

    request概述(封装了客户端所有的请求数据) request是Servlet.service()方法的一个参数,类型为javax.servlet.http.HttpServletRequest.在 ...

  5. mitmproxy 获取请求响应数据

    比较好的一个介绍是:https://blog.wolfogre.com/posts/usage-of-mitmproxy/ mitproxy 获取请求响应数据的代码如下: # -*- coding: ...

  6. request 获取请求参数

    /** * 根据request获取请求的用户参数 * @return * @return */ protected <T> T getParamConvertEntity(Class cl ...

  7. easyui datagrid加载成功之后选定并获取首行数据

    //加载成功之后,选定并获取首行数据 onLoadSuccess:function(data){ alert("grid加载成功"); var rows=$('test').dat ...

  8. sql索引从入门到精通(十亿行数据测试报告)

    原文:sql索引从入门到精通(十亿行数据测试报告) 导读部分 --------------------------------------------------------------------- ...

  9. JS遍历表格获取每行数据及每个单元格数据

    /** * 遍历表格获取每行数据及每个单元格数据 * @param tableID 表格ID */ function GetTable(tableID) { var milasUrl = {};//新 ...

随机推荐

  1. [SNOI2017]遗失的答案

    题目 首先\(G,L\)肯定会满足\(G|L\),否则直接全部输出\(0\) 之后我们考虑一下能用到的质因数最多只有\(8\)个 同时我们能选择的数\(x\)肯定是\(L\)的约数,还得是\(G\)的 ...

  2. 2019 CCPC 湖南全国邀请赛

    A. Chessboard 做法1 单纯形. 做法2 最大费用可行流问题,行列模型. 对每行建一个点,每列建一个点.物品 \(i\) 在 \((r,c)\),那么 \(r\) 向 \(c\) 连流量为 ...

  3. CSS清除默认边距

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquo ...

  4. vue swiper异步加载轮播图,并且懒加载

    参考:https://blog.csdn.net/weixin_38304202/article/details/78282826 效果: 此处安装省略 vue: <div class=&quo ...

  5. Expression表达式 实现and、or搜索

    用法: [HttpPost] public ActionResult GetBannerList(int pageIndex, int pageSize, string search) { Resul ...

  6. 【树剖】CF916E Jamie and Tree

    好吧这其实应该不是树剖... 因为只要求子树就够了,dfs就好了 大概就是记录一个全局根root 多画几幅图会发现修改时x,y以root为根时的lca为以1为根时的lca(x,y),lca(root, ...

  7. python全栈开发:字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存. 1.百分号方式 %[(name ...

  8. AJAX相关概念及应用

    1.Ajax(Asynchronous JavaScript And XML) 异步的JavaScript和XML XML 可扩展标记语言 Ajax是常用的WEB开发技术,是联系前端和后端的桥梁 应用 ...

  9. shell 版本号比较_用shell如何比较软件版本号的大小

    比如你想写个脚本来比较两个版本号 (如"1.2.30" 和"1.3.0")来辨认哪个版本是最新的,有可以比较两个版本号字符串的shell脚本吗? 当你写了一个s ...

  10. scoreboarding

    Reference docs: https://en.wikipedia.org/wiki/Scoreboarding SSC_course_5_Scoreboard_ex.pdf 1, what i ...