关于request请求的基本获取
request对象是从客户端向服务器发出请求,包括用户提交的信息以及客户端的一些信息。
客户端可通过HTML表单或在网页地址后面提供参数的方法提交数据,然后通过request对象的相关方法来获取这些数据。
request的各种方法主要用来处理客户端浏览器提交的请求中的各项参数和选项。
2.requset的常用命令设置
//1.获取请求方式
String method = request.getMethod(); //2.获得请求的资源
String requestURI = request.getRequestURI();
StringBuffer requestURL = request.getRequestURL(); //3.获取web应用的名称
String contextPath = request.getContextPath(); //4.地址后的参数字符串
String queryString = request.getQueryString(); //5.获取客户端信息--获得IP地址
String remoteAddr = request.getRemoteAddr();
3.相应结果

4.完整代码
.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/WEB15/line" method="post">
姓名:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
<input type="submit" value="提交"><br>
</form>
</body>
</html>
Lineservlet
package com.hdh.servlet; import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class LineServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 1.获取请求方式
String method = request.getMethod();
System.out.println("method:" + method); // 2.获得请求的资源
String requestURI = request.getRequestURI();
StringBuffer requestURL = request.getRequestURL();
System.out.println("uri:" + requestURI);
System.out.println("url:" + requestURL); // 3.获取web应用的名称
String contextPath = request.getContextPath();
System.out.println("web应用名称:" + contextPath); // 4.地址后的参数字符串
String queryString = request.getQueryString();
System.out.println("queryString:" + queryString); //5.获取客户端信息--获得IP地址
String remoteAddr = request.getRemoteAddr();
System.out.println("remoteAddr:"+remoteAddr); } protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
} }
5.注意事项
<form action="/WEB15/line" method="post"> action的提交路径为LineServlet 在web.xml中的mapping的访问路径(url-pattern);
关于request请求的基本获取的更多相关文章
- Spring 请求方法的调用原理(Controller)和请求参数的获取的原理
1.请求映射原理 所有的请求都会经过DispatcherServlet这个类,先了解它的继承树 本质还是httpServlet 原理图 测试 request请求携带的参数 从requestMapp ...
- 获取Request请求的路径信息
从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String p ...
- SpringMVC中使用Ajax POST请求以json格式传递参数服务端通过request.getParameter("name")无法获取参数值问题分析
SpringMVC中使用Ajax POST请求以json格式传递参数服务端通过request.getParameter("name")无法获取参数值问题分析 一:问题demo展示 ...
- 页面间传递前端请求参数和获取参数:Model model,HttpServletRequest request, ModelMap map参数使用与区别
Model model, HttpServletRequest request, ModelMap map声明变量 一.下面的方法是需要将请求发过来的数据(或者说参数)传递到重定向的页面/转发的页面的 ...
- 微信小程序request请求动态获取数据
微信小程序开发文档链接 1 后台代码: clickButton:function(){ var that = this; wx.request({ url: 'http://localhost:909 ...
- springMVC中 request请求数据绑定到Controller入参 过程剖析
前言:Controller方法的参数类型可以是基本类型,也可以是封装后的普通Java类型.若这个普通Java类型没有声明任何注解,则意味着它的每一个属性都需要到Request中去查找对应的请求参数.众 ...
- Servlet的学习之Request请求对象(3)
本篇接上一篇,将Servlet中的HttpServletRequest对象获取RequestDispatcher对象后能进行的[转发]forward功能和[包含]include功能介绍完. 首先来看R ...
- Servlet的学习之Request请求对象(2)
在上一篇<Servlet的学习(十)>中介绍了HttpServletRequest请求对象的一些常用方法,而从这篇起开始介绍和学习HttpServletRequest的常用功能. 使用Ht ...
- JavaEE:response响应和request请求
Web服务器接收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象既然代表请求和响应,那么我 ...
随机推荐
- javascript点击兼容所有浏览器封装
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HTML中DOM元素的子节点为空?!firstChild, lastChild, childeNodes[]为空
- How to mount a remote directory in Linux using sshfs
Q. I have access rights to one of the remote server through SSH protocol and there is no File share ...
- vue.js 知识点(三)
---恢复内容开始--- vue和react相同,都是单项数据流,也就是只能从父组件流向子组件,但是因为根据引用的不同,子组件也是可以经过函数处理流向父组件的!这点跟react十分相似,但是也有不同: ...
- codeforces785E
http://codeforces.com/contest/785/problem/E 一道经典的求逆序对的题目,可以用树状数组套平衡树解决 平衡树需要支持插入一个数,删除一个数,找比 x 小的数的个 ...
- 制作基于centos可以ssh连接的容器以及tomcat容器
可以ssh连接的centos容器 参考:http://blog.csdn.net/mexel310/article/details/51705777 一. pull好镜像后,运行容器 1. docke ...
- Jmeter-从数据库中获取数据并作为变量传输
再今天重新学习,从数据库中取数据,并作为变量传到下一个请求中. 首先第一步要导入mysql驱动包 一.添加JDBC Connection Configuration 设置链接 Database URL ...
- Navigator导航器
import React, { Component } from 'react';import { Platform, StyleSheet, Text, View, Navigator, Touch ...
- PHP会话cookie类的封装
<?php header('content-type:text/html;charset=utf-8');/** * 完成cookie的设置.删除.更新.读取 */class Cookie{ ...
- json处理工具类
需要的jar包 <!-- Jackson Json处理工具包 --><dependency><groupId>com.fasterxml.jackson.core& ...