JSP built-in object summary

xiaoxiao2021-03-19  201

In object-oriented programming, the object refers to a variable consisting of an operation and data as a complete entity. Objects are based on a particular model, and the service used in the object uses the object to access the object by a set of methods or related functions, and the client can call these methods to perform a mode. The JSP's built-in object has the following: Request, Response, Out, Session, PageContext, Application, Config, Page. ◆ Request [Request] Object Request object is used to accept all information from the request from the browser to your server. Contact with Request is the HTTPSERVLETREQUEST class. The Request parameter can be obtained by getParameter method, and the type of Request can be obtained by get, post, head, etc., and the introduced HTTP header can be obtained by cookies, Referer et al. ◆ Response [Response] Object Response object is used to send data to the client browser, and the user can use the object to send the server's data to the user-end browser. Contact with Response is the HTTPSERVLETRESPONSE class. ◆ OUT object OUT object is used to output data to the client. ◆ Session [Work] Object session object is used to save objects of each user information to facilitate tracking of the user's operational state. Contact the session is the HttpSession class, and the session is automatically created. Note: The session objects corresponding to different users are generally different. ◆ PageContext object PageContext object is used to manage access to objects that have been named in the special visible section of JSP. A new class in JSP. ◆ Application [Application] Object Application object is used to save information in multiple programs. Used to share information between all users, and can maintain data during the Web application running. Contact Application is the servletContext class, by using getServletConfig (). GetContext () method. Once an Application object is created, the object will remain until the server is turned off. Note: Each user's Application object is the same, and each user uses the same Application object. ◆ Config object config objects are used to configure handles that process the JSP program, and only legal in the JSP page range. It is an object of a servletconfig class. ◆ Page object Page object is only used to save the language in the script is not the time of Java, which is not very practical in Java.

1. The main method of the Request object: ☉ GetAttribute (String Name) Returns the Name property value. ☉ GetaTtributeNames () Returns all attribute names of the Request object. ☉ getCookies () Returns the Cookies object of the client. ☉ GetHeader (String Name) Gets the file header information defined by the HTTP protocol. ☉ GetHeaders (String Name) Returns all values ​​of the Request Header of the specified name. ☉ getMethod () gets the client to transmit data to the server. ☉ getParameter (String Name) Get the parameter value of the client to the server. ☉ getParameterNames () gets the name of all parameters of the client to the server. ☉ getParameterValue (String Name) Get all values ​​of the specified parameter. ☉ getProtocol () Gets the name of the protocol that the client is transferred to the server. ☉ getQueryString () get the query string. ☉ getRequesturi () Get the client address that issues a request string. ☉ getRemoteAddr () Get the IP address of the client. ☉ getRemotehost () Get the name of the client. ☉ GetServerName () Get the name of the server. ☉ GetServletPath () Get the file path of the script file requested by the client. ☉ GetServerPort () Get the port number of the server. ☉ setttribute (String name, java.lang.Object objt) Sets the value of the request parameter named Name, which is specified by the OBJT of the java.lang.object type.

Example: [Request.jsp]

Request Information
jsp Request method: <% = request.getMethod ()%>
Request Uri: <% = Request. getRequesturi ()%>
Request Protocol: <% = Request.getProtocol ()%>
servlet path: <% = request.getServletPath ()%>
Remote User: <% = request.getRemoteuser )%>
Remote address: <%>
Remote Host: <% = request.getRemoteHost ()%>
Path Info: <% = request.getpathinfo ()% >
path translated: <% = request.getPathtranslated ()%>
Query String: <% = Request.getQueryString ()%>
Content Length: <% = Request.getContentLength ()%> < Br> content type: <% = request.getContentType ()%>
Server name: <% = request.getServerName ()%>
Server port: <% = request.getServerPort ()%>
Authorization scheme: <% = request.getauthtype ()%>
the browser you are using is <% = request.getHeader ("user-agent")%>
2, RESPONSE Objects: ☉ AddCookie (Cookie Cook) Add a cookie object to save the client's user information. ☉ Addheader (String Name, String Value) Add HTTP file header information. ☉ ContainSheader (String Name) Determines if the HTTP file header of the specified name already exists. ☉ Senderror (int) sends an error information to the client. ☉ SetHeader (String Name, String Value) Sets the value of the HTTP file header of the specified name.

Example: Timed refresh [refresh.jsp] <% @ page contentty = "text / html; charSet = GB2312"%> <% @ page import = "java.util.date"%> Timed refresh page </ title> </ head> <body> <b> This page is used to illustrate the response object </ b> <br> <b> Current time is: </ b> <% response.setheader ("Refresh "," 10 ");%> <% out.println (new Date ());%> </ body> </ html> 3, OUT object Main method: ☉ Out.print / println (Boolean | char | char [] | double | float | int | long | Object | String |) Output various types of data. ☉ Out.newline () Outputs a wrap character. ☉ Out.flush () Outputs the data in the buffer. ☉ Out.close () Turn off the output stream. ☉ Out.clearbuffer () Clear the data in the buffer and output the data to the client. ☉ Out.clear () Clear the data in the buffer, but does not output the data to the client. ☉ Out.getBuffersize () Get the size of the buffer. ☉ Out.getRemaining () Get the size of the space that is not occupied in the buffer. ☉ Out.isautoflush () Returns the Boolean value. 4, the main method of session object: ☉ GetaTtribute (String Name) Get information that is associated with the specified name Name. ☉ GetAttributeNames () Returns every property object stored in the Session object. ☉ getCreationTime () Returns the time created by Session. ☉ GetId () returns the unique identifier to generate it for every session. ☉ getLastAccessedTime () Returns the time that the current session object is last sent by the customer. ☉ getMaxinactiveInterval () Returns the total time (seconds). ☉ RemoveAttribute (String Name) Deletes information about the associated name Name. ☉ SetAttribute (String Name, Java.lang.Object Value) Sets the property value value value specified Name and stores in the Session object. 5, PageContext object main method: ☉ gettribute scope () Retrieves a specific range of naming objects. ☉ FindAttribute () is used to implement a search for a named property in order to follow the order requested, session, and application range. ☉ SetAttribute () is used to set the named object in the range or specific range of the default page. ☉ RemoveAttribute () is used to delete the default page range or the object already named. 6, the main method of Application object: ☉ gettribute (String Name) Returns the value of the attribute of the name Application object specified by Name. ☉ gettributenames () Returns the name of all the properties of all Application objects. ☉ GetInitParameter (String Name) Returns the initial value of an attribute of an Application object specified by name.</p> <p>☉ GetServletInfo () Returns the current version of the servlet compiler.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-130132.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="130132" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.042</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'e3rGqikdyLoQYyoNGypNBoMRSzaBXwTOtcyqQftlYJy90zl17u7cH92IpH2ITHajWARL5hCgezJk5_2FV1Rz1P5g_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>