When a user sends a request to the client, such as [plain] view plaincopyhttp: // localhost: 8088/ServApp/myreq. cg? Param1 = param when a Socket request arrives at the server (assuming it is a Tomcat server), after a series of encapsulation processes on the Tomcat server, the request is encapsulated into an HttpServletRequest object and handed over to the corresponding Servlet. The Simple Sequence diagram is as follows: Here, we only focus on step 1. In step 2, the request object is passed to the Container component for execution. When the Servlet object obtains the request (httpservletrequest), it calls the relevant function (Service) for processing. Below is a simple example to illustrate the current step. 1. Compile the request processing class (EntryServ) [java] package com. serv; import java. io. IOException; import java. io. printWriter; import javax. servlet. requestDispatcher; import javax. servlet. servletContext; import javax. servlet. servletException; import javax. servlet. http. cookie; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; public class Entry Serv extends HttpServlet {/*****/private static final long serialVersionUID = 1L; @ Override protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// TODO Auto-generated method stub ServletContext serv = getServletContext (); // obtain request-related information String Contextpath = req. getContextPath (); String CharacterEncoding = req. getCharacterEncoding (); Stri Ng ContentType = req. getContentType (); String LocalAddr = req. getLocalAddr (); String LocalName = req. getLocalName (); String Method = req. getMethod (); String Parameter = req. getParameter ("param1"); String Protocol = req. getProtocol (); String ServerName = req. getServerName (); Cookie [] Cookies = req. getCookies (); String ServletPath = req. getServletPath (); String RemoteAddr = req. getRemoteAddr (); Stri Ng RemoteHost = req. getRemoteHost (); String RequestURI = req. getRequestURI (); String RequestedSessionId = req. getRequestedSessionId (); req. setCharacterEncoding ("gbk"); req. setAttribute ("oneattr", "setted"); // response responds to the request and outputs some resp content of the request. setContentType ("text/html; charset = gbk"); // set the response page character encoding PrintWriter out = resp. getWriter (); out. println ("<font color = red>