前言:HttpServletRequest对象封装了客户端进行HTTP协议请求时的所有信息,HttpServletRequest继承了ServletRequest,所以和ServletRequest一样,是由tomcat服务器提供实现的。具体过程如下:

1)Web客户向Servlet容器发出Http请求;

2)Servlet容器解析Web客户的Http请求;

3)Servlet容器创建一个HttpRequest对象,在这个对象中封装Http请求信息;



1.HttpServlet

说到HttpServletRequest就不得不说一下HttpServlet,下面看它的API:

javax.servlet.http

Class HttpServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
All Implemented Interfaces:
Serializable,Servlet,ServletConfig
Method Summary
protected  void doDelete(HttpServletRequest req,HttpServletResponse resp)

          Called by the server (via the service method) to allow a servlet to handle a DELETE request.
protected  void doGet(HttpServletRequest req,HttpServletResponse resp)

          Called by the server (via the service method) to allow a servlet to handle a GET request.
protected  void doHead(HttpServletRequest req,HttpServletResponse resp)

          Receives an HTTP HEAD request from the protected service method and handles the request.
protected  void doOptions(HttpServletRequest req,HttpServletResponse resp)

          Called by the server (via the service method) to allow a servlet to handle a OPTIONS request.
protected  void doPost(HttpServletRequest req,HttpServletResponse resp)

          Called by the server (via the service method) to allow a servlet to handle a POST request.
protected  void doPut(HttpServletRequest req,HttpServletResponse resp)

          Called by the server (via the service method) to allow a servlet to handle a PUT request.
protected  void doTrace(HttpServletRequest req,HttpServletResponse resp)

          Called by the server (via the service method) to allow a servlet to handle a TRACE request.
protected  long getLastModified(HttpServletRequest req)

          Returns the time the HttpServletRequest object was last modified, in milliseconds since midnight January 1, 1970 GMT.
protected  void service(HttpServletRequest req,HttpServletResponse resp)

          Receives standard HTTP requests from the public service method and dispatches them to thedoXXX methods defined in this class.
 void service(ServletRequest req,ServletResponse res)

          Dispatches client requests to the protected service method.

可以看到HttpServlet实现了servlet接口,所以其中的service(ServletRequest req,ServletResponse res)方法和servlet中的一致,在每次请求时调用。只抽取部分方法,概要信息如下:

(1).doGet(HttpServletRequest req,HttpServletResponse resp):接收HTTP的GET请求;

(2).doPost(HttpServletRequest req,HttpServletResponse resp):接收HTTP的POST请求;

(3).service(HttpServletRequest req,HttpServletResponse resp):接收HTTP请求,并把它分配到doXXX方法中;





2.HttpServletRequest的API:

javax.servlet.http

Interface HttpServletRequest

All Superinterfaces:
ServletRequest
All Known Implementing Classes:
HttpServletRequestWrapper
 String getAuthType()

          Returns the name of the authentication scheme used to protect the servlet.
 String getContextPath()

          Returns the portion of the request URI that indicates the context of the request.
 Cookie[] getCookies()

          Returns an array containing all of the Cookie objects the client sent with this request.
 long getDateHeader(String name)

          Returns the value of the specified request header as a long value that represents aDate object.
 String getHeader(String name)

          Returns the value of the specified request header as a String.
 Enumeration getHeaderNames()

          Returns an enumeration of all the header names this request contains.
 Enumeration getHeaders(String name)

          Returns all the values of the specified request header as an Enumeration ofString objects.
 int getIntHeader(String name)

          Returns the value of the specified request header as an int.
 String getMethod()

          Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
 String getPathInfo()

          Returns any extra path information associated with the URL the client sent when it made this request.
 String getPathTranslated()

          Returns any extra path information after the servlet name but before the query string, and translates it to a real path.
 String getQueryString()

          Returns the query string that is contained in the request URL after the path.
 String getRemoteUser()

          Returns the login of the user making this request, if the user has been authenticated, ornull if the user has not been authenticated.
 String getRequestedSessionId()

          Returns the session ID specified by the client.
 String getRequestURI()

          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.
 StringBuffer getRequestURL()

          Reconstructs the URL the client used to make the request.
 String getServletPath()

          Returns the part of this request's URL that calls the servlet.
 HttpSession getSession()

          Returns the current session associated with this request, or if the request does not have a session, creates one.
 HttpSession getSession(boolean create)

          Returns the current HttpSession associated with this request or, if there is no current session andcreate is true, returns a new session.
 Principal getUserPrincipal()

          Returns a java.security.Principal object containing the name of the current authenticated user.
 boolean isRequestedSessionIdFromCookie()

          Checks whether the requested session ID came in as a cookie.
 boolean isRequestedSessionIdFromUrl()

          Deprecated. As of Version 2.1 of the Java Servlet API, useisRequestedSessionIdFromURL()
instead.
 boolean isRequestedSessionIdFromURL()

          Checks whether the requested session ID came in as part of the request URL.
 boolean isRequestedSessionIdValid()

          Checks whether the requested session ID is still valid.
 boolean isUserInRole(String role)

          Returns a boolean indicating whether the authenticated user is included in the specified logical "role".

这里只列举常用的几个方法(有些API中没有列举到的,是在ServletRequest中已有的方法):

(1)获得客户机信息                                                                       



getRequestURL():返回客户端发出请求时的完整URL。

getRequestURI():返回请求行中的资源名部分。

getQueryString() :返回请求行中的参数部分。

getRemoteAddr():返回发出请求的客户机的IP地址。

getRemoteHost() :返回发出请求的客户机的完整主机名。

getRemotePort():返回客户机所使用的网络端口号。

getLocalAddr() :返回WEB服务器的IP地址。

getLocalName():返回WEB服务器的主机名。

(2)获得客户机请求头                                                                    



getHeaders(String name):获得请求头信息组成的Enumeration。



(3)获得客户机请求参数(客户端提交的数据)                                            



getParameterMap():获取参数名和参数值的String[]组成的键值对,即返回的类型为Map(String,String[]),用于多参数值。





3.项目的目录结构

4.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>javaWeb_07</display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>httpRequestDemo</servlet-name>
<servlet-class>com.dao.chu.HttpRequestDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>httpRequestDemo</servlet-name>
<url-pattern>/httpRequest</url-pattern>
</servlet-mapping>
</web-app>

5.login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>登陆页</title>
</head>
<body> <!-- 相对路径写action="httpRequest"; -->
<!-- 绝对路径写action="/javaWeb_07/httpRequest"; --> <form action="httpRequest" method="get">
用户名:<input type="text" name="user">
<br><br>
密码  <input type="password" name="password">
<br><br> <!-- 一组信息 -->
interesting:
<input type="checkbox" name="interesting" value="reading">Reading
<input type="checkbox" name="interesting" value="writing">Writing
<input type="checkbox" name="interesting" value="football">Football
<input type="checkbox" name="interesting" value="game">Game
<input type="checkbox" name="interesting" value="shopping">Shopping
<input type="checkbox" name="interesting" value="party">Party
<input type="checkbox" name="interesting" value="TV">TV <br><br> <input type="submit" value="提交">
</form> </body>
</html>

6.HttpRequestDemo.java,分三种情况,对应后面的三种现象

(1)只写一个service方法

package com.dao.chu;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
*
* <p>
* Title: HttpRequestDemo Description:继承了HttpServlet的测试类
* </p>
*/
public class HttpRequestDemo extends HttpServlet { /** serialVersionUID */
private static final long serialVersionUID = 1L; // 得到请求的URL地址
String requestUrl = "";
// 得到请求行中的资源部分
String requestUri = "";
// 得到请求的URL地址中附带的参数
String queryString = "";
// 得到来访者的IP地址
String remoteAddr = "";
// 来访者主机名
String remoteHost = "";
// 客户机所使用的网络端口号
int remotePort = 0;
// 得到请求方式GET/POST
String method = "";
// 获取WEB服务器的IP地址
String localAddr = "";
// 获取WEB服务器的主机名
String localName = ""; /**
* 继承了HttpServlet的service方法
*/
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { //调用公共输出方法
commonPrint(request, response); } /**
* Title: commonPrint
* Description:公共输出方法
* @param request
* @param response
*/
private void commonPrint(HttpServletRequest request,
HttpServletResponse response) { // 设置将字符以"UTF-8"编码输出到客户端浏览器
response.setCharacterEncoding("UTF-8");
// 通过设置响应头控制浏览器以UTF-8的编码显示数据,如果不加这句话,那么浏览器显示的将是乱码
response.setHeader("content-type", "text/html;charset=UTF-8"); requestUrl = request.getRequestURL().toString();
requestUri = request.getRequestURI();
queryString = request.getQueryString();
remoteAddr = request.getRemoteAddr();
method = request.getMethod();
localAddr = request.getLocalAddr();
localName = request.getLocalName(); PrintWriter out;
try {
out = response.getWriter(); out.write("<hr/>");
out.write("(1)获取客户机信息:");
out.write("<br/>");
out.write("请求的URL地址:" + requestUrl);
out.write("<br/>");
out.write("请求的资源:" + requestUri);
out.write("<br/>");
out.write("请求的URL地址中附带的参数:" + queryString);
out.write("<br/>");
out.write("来访者的IP地址:" + remoteAddr);
out.write("<br/>");
out.write("来访者的主机名:" + remoteHost);
out.write("<br/>");
out.write("使用的端口号:" + remotePort);
out.write("<br/>");
out.write("请求的方式:" + method);
out.write("<br/>");
out.write("服务器的IP地址:" + localAddr);
out.write("<br/>");
out.write("服务器的主机名:" + localName); // 获取的客户机的请求头信息
out.write("<br/>");
out.write("<hr/>");
out.write("(2)获取客户机的请求头信息:");
out.write("<br/>"); // 得到所有请求头名组成的Enumeration
Enumeration<String> headerNames = request.getHeaderNames(); // 循环
while (headerNames.hasMoreElements()) { // 得到所有的请求头名
String headerName = (String) headerNames.nextElement();
// 根据请求头名得到所有请求头值
String headerValue = request.getParameter(headerName);
out.write(headerName + ": " + headerValue);
out.write("<br/>");
} // 获取的客户机的请求信息
out.write("<br/>");
out.write("<hr/>");
out.write("(3)获取客户机的请求信息:");
out.write("<br/>"); // 获取参数名和参数值的String[]组成的键值对
Map<String, String[]> map = request.getParameterMap();
Set<Entry<String, String[]>> entrySet = map.entrySet();
for (Entry<String, String[]> entry : entrySet) { out.write(entry.getKey() + ": "
+ Arrays.asList(entry.getValue()));
out.write("<br/>");
} } catch (IOException e) {
e.printStackTrace();
} } }

(2)写有service方法,doget方法,dopost方法

package com.dao.chu;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
*
* <p>
* Title: HttpRequestDemo Description:继承了HttpServlet的测试类
* </p>
*/
public class HttpRequestDemo extends HttpServlet { /** serialVersionUID */
private static final long serialVersionUID = 1L; // 得到请求的URL地址
String requestUrl = "";
// 得到请求行中的资源部分
String requestUri = "";
// 得到请求的URL地址中附带的参数
String queryString = "";
// 得到来访者的IP地址
String remoteAddr = "";
// 来访者主机名
String remoteHost = "";
// 客户机所使用的网络端口号
int remotePort = 0;
// 得到请求方式GET/POST
String method = "";
// 获取WEB服务器的IP地址
String localAddr = "";
// 获取WEB服务器的主机名
String localName = ""; /**
* 继承了HttpServlet的service方法
*/
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { System.out.println("调用了service方法");
//调用公共输出方法
commonPrint(request, response); } /**
* 继承了HttpServlet的doGet方法
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("调用了doGet方法");
//调用公共输出方法
commonPrint(request, response);
} /**
* 继承了HttpServlet的doPost方法
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("调用了doPost方法");
//调用公共输出方法
commonPrint(request, response);
} /**
* Title: commonPrint
* Description:公共输出方法
* @param request
* @param response
*/
private void commonPrint(HttpServletRequest request,
HttpServletResponse response) { // 设置将字符以"UTF-8"编码输出到客户端浏览器
response.setCharacterEncoding("UTF-8");
// 通过设置响应头控制浏览器以UTF-8的编码显示数据,如果不加这句话,那么浏览器显示的将是乱码
response.setHeader("content-type", "text/html;charset=UTF-8"); requestUrl = request.getRequestURL().toString();
requestUri = request.getRequestURI();
queryString = request.getQueryString();
remoteAddr = request.getRemoteAddr();
method = request.getMethod();
localAddr = request.getLocalAddr();
localName = request.getLocalName(); PrintWriter out;
try {
out = response.getWriter(); out.write("<hr/>");
out.write("(1)获取客户机信息:");
out.write("<br/>");
out.write("请求的URL地址:" + requestUrl);
out.write("<br/>");
out.write("请求的资源:" + requestUri);
out.write("<br/>");
out.write("请求的URL地址中附带的参数:" + queryString);
out.write("<br/>");
out.write("来访者的IP地址:" + remoteAddr);
out.write("<br/>");
out.write("来访者的主机名:" + remoteHost);
out.write("<br/>");
out.write("使用的端口号:" + remotePort);
out.write("<br/>");
out.write("请求的方式:" + method);
out.write("<br/>");
out.write("服务器的IP地址:" + localAddr);
out.write("<br/>");
out.write("服务器的主机名:" + localName); // 获取的客户机的请求头信息
out.write("<br/>");
out.write("<hr/>");
out.write("(2)获取客户机的请求头信息:");
out.write("<br/>"); // 得到所有请求头名组成的Enumeration
Enumeration<String> headerNames = request.getHeaderNames(); // 循环
while (headerNames.hasMoreElements()) { // 得到所有的请求头名
String headerName = (String) headerNames.nextElement();
// 根据请求头名得到所有请求头值
String headerValue = request.getParameter(headerName);
out.write(headerName + ": " + headerValue);
out.write("<br/>");
} // 获取的客户机的请求信息
out.write("<br/>");
out.write("<hr/>");
out.write("(3)获取客户机的请求信息:");
out.write("<br/>"); // 获取参数名和参数值的String[]组成的键值对
Map<String, String[]> map = request.getParameterMap();
Set<Entry<String, String[]>> entrySet = map.entrySet();
for (Entry<String, String[]> entry : entrySet) { out.write(entry.getKey() + ": "
+ Arrays.asList(entry.getValue()));
out.write("<br/>");
} } catch (IOException e) {
e.printStackTrace();
} } }

(3)写有service方法,doget方法,dopost方法,且service方法调用了父类的service(HttpServletRequest req,HttpServletResponse resp)方法。

package com.dao.chu;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
*
* <p>
* Title: HttpRequestDemo Description:继承了HttpServlet的测试类
* </p>
*/
public class HttpRequestDemo extends HttpServlet { /** serialVersionUID */
private static final long serialVersionUID = 1L; // 得到请求的URL地址
String requestUrl = "";
// 得到请求行中的资源部分
String requestUri = "";
// 得到请求的URL地址中附带的参数
String queryString = "";
// 得到来访者的IP地址
String remoteAddr = "";
// 来访者主机名
String remoteHost = "";
// 客户机所使用的网络端口号
int remotePort = 0;
// 得到请求方式GET/POST
String method = "";
// 获取WEB服务器的IP地址
String localAddr = "";
// 获取WEB服务器的主机名
String localName = ""; /**
* 继承了HttpServlet的service方法
*/
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { System.out.println("调用了service方法");
//调用公共输出方法
commonPrint(request, response); //依旧调用父类的方法
super.service(request, response); } /**
* 继承了HttpServlet的doGet方法
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("调用了doGet方法");
//调用公共输出方法
commonPrint(request, response);
} /**
* 继承了HttpServlet的doPost方法
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("调用了doPost方法");
//调用公共输出方法
commonPrint(request, response);
} /**
* Title: commonPrint
* Description:公共输出方法
* @param request
* @param response
*/
private void commonPrint(HttpServletRequest request,
HttpServletResponse response) { // 设置将字符以"UTF-8"编码输出到客户端浏览器
response.setCharacterEncoding("UTF-8");
// 通过设置响应头控制浏览器以UTF-8的编码显示数据,如果不加这句话,那么浏览器显示的将是乱码
response.setHeader("content-type", "text/html;charset=UTF-8"); requestUrl = request.getRequestURL().toString();
requestUri = request.getRequestURI();
queryString = request.getQueryString();
remoteAddr = request.getRemoteAddr();
method = request.getMethod();
localAddr = request.getLocalAddr();
localName = request.getLocalName(); PrintWriter out;
try {
out = response.getWriter(); out.write("<hr/>");
out.write("(1)获取客户机信息:");
out.write("<br/>");
out.write("请求的URL地址:" + requestUrl);
out.write("<br/>");
out.write("请求的资源:" + requestUri);
out.write("<br/>");
out.write("请求的URL地址中附带的参数:" + queryString);
out.write("<br/>");
out.write("来访者的IP地址:" + remoteAddr);
out.write("<br/>");
out.write("来访者的主机名:" + remoteHost);
out.write("<br/>");
out.write("使用的端口号:" + remotePort);
out.write("<br/>");
out.write("请求的方式:" + method);
out.write("<br/>");
out.write("服务器的IP地址:" + localAddr);
out.write("<br/>");
out.write("服务器的主机名:" + localName); // 获取的客户机的请求头信息
out.write("<br/>");
out.write("<hr/>");
out.write("(2)获取客户机的请求头信息:");
out.write("<br/>"); // 得到所有请求头名组成的Enumeration
Enumeration<String> headerNames = request.getHeaderNames(); // 循环
while (headerNames.hasMoreElements()) { // 得到所有的请求头名
String headerName = (String) headerNames.nextElement();
// 根据请求头名得到所有请求头值
String headerValue = request.getParameter(headerName);
out.write(headerName + ": " + headerValue);
out.write("<br/>");
} // 获取的客户机的请求信息
out.write("<br/>");
out.write("<hr/>");
out.write("(3)获取客户机的请求信息:");
out.write("<br/>"); // 获取参数名和参数值的String[]组成的键值对
Map<String, String[]> map = request.getParameterMap();
Set<Entry<String, String[]>> entrySet = map.entrySet();
for (Entry<String, String[]> entry : entrySet) { out.write(entry.getKey() + ": "
+ Arrays.asList(entry.getValue()));
out.write("<br/>");
} } catch (IOException e) {
e.printStackTrace();
} } }

7.填写jsp页面表单,发出HTTP请求

8.三种情况的现象

(1)页面显示

控制台无输出,说明成功调用了service方法。

(2)页面显示

控制台输出:

说明虽然写了dopost和doget方法,但是却没有接收到请求。

(3)页面显示

控制台打印:

很显然这次接收到了doGET方法

8.为了追求根源,我们找到HttpServlet的service方法的源码:

/**
* <p>Title: HttpServlet的service方法的源码</p>
* <p>Description: </p>
* @throws ServletException
* @throws IOException
*/
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String method = req.getMethod();
if (method.equals("GET")) {
long lastModified = getLastModified(req);
if (lastModified == -1L) { doGet(req, resp);
} else {
long ifModifiedSince;
try {
ifModifiedSince = req.getDateHeader("If-Modified-Since");
} catch (IllegalArgumentException iae) {
ifModifiedSince = -1L;
}
if (ifModifiedSince < lastModified / 1000L * 1000L) { maybeSetLastModified(resp, lastModified);
doGet(req, resp);
} else {
resp.setStatus(304);
}
}
} else if (method.equals("HEAD")) {
long lastModified = getLastModified(req);
maybeSetLastModified(resp, lastModified);
doHead(req, resp);
} else if (method.equals("POST")) {
doPost(req, resp);
} else if (method.equals("PUT")) {
doPut(req, resp);
} else if (method.equals("DELETE")) {
doDelete(req, resp);
} else if (method.equals("OPTIONS")) {
doOptions(req, resp);
} else if (method.equals("TRACE")) {
doTrace(req, resp); } else { String errMsg = lStrings.getString("http.method_not_implemented");
Object[] errArgs = new Object[1];
errArgs[0] = method;
errMsg = MessageFormat.format(errMsg, errArgs); resp.sendError(501, errMsg);
}
}

我们可以看到

String method = req.getMethod();if (method.equals("GET")){doGet(req, resp);}等

的确有接收请求的方式,根据判断的请求方式转到相应的方法。而我们在(2)中继承了HttpServlet,覆盖了service方法,没有调用原来父类的方法,所以即使写了doget和dopost也接收不到请求。

附:

本次项目源码:点击打开链接

javaWEB总结(7):HttpServlet和HttpServletRequest的更多相关文章

  1. javaWEB中的HttpServlet(企业开发使用)

    HttpServlet: 1). 是一个 Servlet, 继承自 GenericServlet. 针对于 HTTP 协议所定制. 2). 在 service() 方法中直接把 ServletReuq ...

  2. javaWEB总结(10):HttpServlet成长史

    前言: 从Servlet,ServletConfig到GenericServlet再到Httpservlet的整个过程,相当于Httpservlet的成长史,我们不需要写那么臃肿的代码,开发难度由复杂 ...

  3. JAVAWEB开发之HttpServletResponse和HttpServletRequest详解(下)(各种乱码、验证码、重定向和转发)

    HttpServletRequest获取请求头信息  (1)获取客户机请求头 String getHeader(String name) Enumeration<String> getHe ...

  4. [原创]java WEB学习笔记11:HttpServlet(HttpServletRequest HttpServletRsponse) 以及关于 Servlet 小结

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  5. JAVAWEB开发之HttpServletResponse和HttpServletRequest详解(上)(各种乱码、验证码、重定向和转发)

    HttpServletResponse简介 Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象 request和re ...

  6. [转]【HttpServlet】HttpServletRequest接口

    建立时间:2019.6.28 &6.29 1.HttpServletRequest概述 我们在创建Servlet时会覆盖service()方法,或doGet()/doPost(),这些方法都有 ...

  7. Javaweb学习笔记——上传下载文件

    一.前言 在Javaweb中,上传下载是经常用到的功能,对于文件上传,浏览器在上传的过程中是以流的过程将文件传给服务器,一般都是使用commons-fileupload这个包实现上传功能,因为comm ...

  8. JavaWeb结合七牛云存储搭建个人相册服务

    JavaWeb结合七牛云存储搭建个人相册服务 一.引言1. 课程概述 相信很多人都知道网站一般会有很多图片,对于小型网站来说,图片放在网站服务器上不算什么,但当图片数量很大时,会造成服务器很臃肿,相应 ...

  9. log4j在javaWeb项目中的使用

    在前边的文章中对log4j的配置文件进行了说明,今天介绍如何在普通的javaWeb项目中使用log4j. 在日常的开发过程中,日志使用的很频繁,我们可以利用日志来跟踪程序的错误,程序运行时的输出参数等 ...

随机推荐

  1. old linkedin profile

    employments: software engineer intern: Karl Storz Imaging, 2015-06 to 2015-09. software engineer int ...

  2. curl 命令使用总结

    curl 查看网页源码 curl www.sina.com 保存页面 -o curl -o [文件名] www.sina.com 直接在curl命令后加上网址,就可以看到网页源码. 如果要把这个网页保 ...

  3. 动态调用WCF

    最近在做的一个项目中需要动态调用WCF地址,因为有很多终端服务器,而每台终端服务器上都部署一个WCF服务,中央服务器需要不定时调用其中某个或者多个WCF服务执行相关操作,因此添加引用及配置文件配置的方 ...

  4. 用户输入密码隐藏之getpass的使用

    有的时候,比如商城登录的时候,我希望输入的时候我的密码不为明文,如何实现呢? 这里就需要利用getpass模块中的getpass方法.注意,需要在linux上或者windows下运行,在pycharm ...

  5. php中函数 vsprintf() 和 var_export()

    把格式化字符串写入变量中: <?php $number = 9; $str = "Beijing"; $txt = vsprintf("There are %u m ...

  6. PHP单例模式--典型的三私一公

    单例模式:即一个类只被实例化一次,当其他人对其再次实例化时,便返回第一次实例化的对象.这种模式可以极大地节约资源.典型应用于数据库类的实例化. 以实例化一个Mysql数据库类为例: 要实现一个类只实例 ...

  7. boolean attribute(布尔值属性) attribute vs property

    boolean attribute(布尔值属性) boolean attribute     HTML - Why boolean attributes do not have boolean val ...

  8. 一个小时快速搭建微信小程序

    「小程序」这个划时代的产品发布快一周了,互联网技术人都在摩拳擦掌,跃跃欲试.可是小程序目前还在内测,首批只发放了 200 个内测资格(泪流满面).本以为没有 AppID 这个月就与小程序无缘了,庆幸的 ...

  9. hdfs格式化hadoop namenode -format错误

    在对HDFS格式化,执行hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示: [shirdrn@localhost bin]$ hadoop namenod ...

  10. Windows下WordPress搭建博客过程

    搭建环境:Win7 + XAMPP5.5 + wordpress4.5.1 官网下载安装包,解压,拷贝到网站根目录(D:\IT\XAMPP5.5\htdocs\),重命名为blog(随意) 创建数据库 ...