request方法总结
1.获得指定的头
String header = response.getHeader("user-agent");
2.获得所有头的名称
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {// 判断是否还有下一个元素
String nextElement = headerNames.nextElement();// 获取headerNames集合中的请求头
String header2 = request.getHeader(nextElement);// 通过请求头得到请求内容
System.out.println(nextElement + ":" + header2); }
3.获取请求方式
String method = request.getMethod();
4.获得请求的资源
String requestURI = request.getRequestURI();
StringBuffer requestURL = request.getRequestURL();
5.获取web应用的地址名称
String contextPath = request.getContextPath();
6.获取地址后的参数字符串
String queryString = request.getQueryString();
7.获取客户端信息--获得IP地址
String remoteAddr = request.getRemoteAddr();
8.获取单个表单中的value值
String usernam = request.getParameter("usernam");
9.获取多个表单的value值
String[] parameterValues = request.getParameterValues("hobby");
System.out.print("hobby.values:");
for (String string : parameterValues) {
System.err.print(string + " ");
}
10.获得所有参数的name
Enumeration<String> parameterNames = request.getParameterNames();
for (String string2 : parameterValues) {
System.out.println(parameterNames.nextElement()); }
11.将获得的所有参数封装到一个Map<String,String[]>中
Map<String, String[]> parameterMap = request.getParameterMap();
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
System.out.println(entry.getKey());
for (String string : entry.getValue()) {
System.out.println(string);
}
System.out.println("----------------");
}
12.跳转方式
1.转发:地址不变
request.getRequestDispatcher("path").forward(request, response);
2.重定向:地址改变
response.sendRedirect(path);
13.向request域中存储和取出数据
request.setAttribute("name", "value");
request.getAttribute("name");
request方法总结的更多相关文章
- 利用Filter和拦截器,将用户信息动态传入Request方法
前言: 在开发当中,经常会验证用户登录状态和获取用户信息.如果每次都手动调用用户信息查询接口,会非常的繁琐,而且代码冗余.为了提高开发效率,因此就有了今天这篇文章. 思路: 用户请求我们的方法会携带一 ...
- nodejs -- http模块. request() 方法 , get方法.
1. request方法: 提交评论到慕课网: var http = require('http'); var querystring = require('querystring'); var po ...
- Ext.Ajax.request方法 参数
json数据服务器回传的方法. 在api总指出回传的格式{success;true,data:{clientName: "Fred. Olsen Lines", portOfL ...
- 20191011-构建我们公司自己的自动化接口测试框架-Action的request方法封装
Action模块 封装接口request方法,根据传入的参数调用不同的请求方法,因为项目特色,我们公司的接口都是get和post方法,所以仅仅封装了get和post方法: import request ...
- Asp.net Request方法获取客户端的信息
Response.Write("客户端计算机名:" + Request.UserHostName + "<BR />"); Response.Wri ...
- 如何在JS中获取Request方法
方法 function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = ne ...
- 基于Promise封装uni-app的request方法,实现类似axios形式的请求
https://my.oschina.net/u/2428630/blog/3004860 uni-app框架中 安装(项目根目录下运行) npm install uni-request --save ...
- 微信小程序--后台交互/wx.request({})方法/渲染页面方法 解析
小程序的后台获取数据方式get/post具体函数格式如下:wx.request({}) data: { logs:[] }, onLoad:function(){ this.getdata(); } ...
- 获取Session和request方法
action中的几种写法 //第一种很少用public class LoginAction1 extends ActionSupport { private Map request; ...
- HttpServletRequest request方法详解
//1.获取请求参数 //获取参数的单个值,如有多个则只返回第一个 String parameter1 = request.getParameter("demo"); //获取参数 ...
随机推荐
- code::blocks学习(2)
转自: http://blog.csdn.net/sinat_27088253/article/details/52137855 http://jingyan.baidu.com/article/0b ...
- 【OCP-12c】CUUG最新考试原题整理及答案(071-11)
11.(5-8) choose the best answer: Examine the structure of the BOOKS_TRANSACTIONS table. You want to ...
- OCP 12c最新考试原题及答案(071-3)
3.(4-10) choose the best answer:The user SCOTT who is the owner of ORDERS and ORDER_ITEMS tables iss ...
- jQuery实现ie浏览器兼容placeholder效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- bzoj4199: [Noi2015]品酒大会(后缀数组)
题目描述 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战 两个环节,分别向优胜者颁发“首席品酒家”和“首席猎手”两个奖项,吸引了众多品酒师参加. 在大会的晚餐上,调酒师 Rainb ...
- PHP程序执行流程
1, PHP文件一定放在服务器的,但是PHP中不同的内容会在不同的地方执行.下图演示了浏览器请求一个php页面的流程. 2,时序图如下所示,在浏览器中输入url后,首先去本机hosts文件中解析ip地 ...
- MySql数据库,对varchar类型字段str进行where str=0条件查询时,查询结果是什么
在用MySQL查询数据的时候,遇到了一个奇怪的问题.用一个varchar类型的字符串str,作为条件与0比较时,会查str不为0的数据. 比如:SELECT id, idnumber from hr_ ...
- [ActionScript 3.0] SharedObject的用法简介
package com.models { import flash.net.SharedObject; /** * @author * @E-mail * @create 2015-6-12 下午2: ...
- Setup "EQGRP_Lost_in_Translation" Of NAS
Setup "EQGRP_Lost_in_Translation" Of NAS 1.前言: 北京时间4月14号晚,TheShadowBrokers在steemit.com博客上放 ...
- debian下安装 locale 并设置 zh_CN.UTF-8 [转]
root@Linkstation :~# apt-get install locales root@Linkstation:~# dpkg-reconfigure locales root@Links ...