JSP built-in object (2)

zhaozj2021-02-16  96

The previous chapter mainly tells the concept of JSP built-in object; this time, this time, some ways to build a built-in object.

1, the main method of request object:

☉ gettribute (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: <% = request.getRemoteAdddr ()%>


Remote host: <% = request.getRemoteHost ()%>


Path Info: <% = request.getPathInfo ()%>


Path Translated: <% = request.getPathTranslated ()%>


Query String: <% = request.getQueryString ()%>


Content Length: <% = Request.getContentLength ()%>


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, the main method of response object:

☉ 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 ContentType = "text / html; charset = GB2312"%>

<% @ Page Import = "java.util.date"%>

Timed Refresh Page </ Title></p> <p></ hEAD></p> <p><body></p> <p><b> This page is used to illustrate the response object </ b></p> <p><br></p> <p><b> The current time is: </ b></p> <p><% response.setHeader ("Refresh", "10");%></p> <p><%</p> <p>Out.println (New Date ());</p> <p>%></p> <p></ body></p> <p></ html></p> <p>3, OUT object main method:</p> <p>☉ Out.print / Println (Boolean | Char | Char [] | Double | FLOAT | INT | Long | Object | String |) Outputs various types of data.</p> <p>☉ Out.newline () Outputs a wrap character.</p> <p>☉ Out.flush () Outputs the data in the buffer.</p> <p>☉ Out.close () Turn off the output stream.</p> <p>☉ Out.clearbuffer () Clear the data in the buffer and output the data to the client.</p> <p>☉ Out.clear () Clear the data in the buffer, but does not output the data to the client.</p> <p>☉ Out.getBuffersize () Get the size of the buffer.</p> <p>☉ Out.getRemaining () Get the size of the space that is not occupied in the buffer.</p> <p>☉ Out.isautoflush () Returns the Boolean value.</p> <p>4, the main method of session object:</p> <p>☉ GetaTtribute (String Name) Get information that is associated with the specified name Name.</p> <p>☉ GetAttributeNames () Returns every property object stored in the Session object.</p> <p>☉ getCreationTime () Returns the time created by Session.</p> <p>☉ 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.</p> <p>☉ getMaxinactiveInterval () Returns the total time (seconds).</p> <p>☉ RemoveAttribute (String Name) Deletes information about the associated name Name.</p> <p>☉ SetAttribute (String Name, Java.lang.Object Value) Sets the property value value value specified Name and stores in the Session object.</p> <p>5, PageContext object main method:</p> <p>☉ gettribute scope () Retrieves a range of specific named objects.</p> <p>☉ FindAttribute () is used to implement a search for a named property in order to follow the order requested, session, and application range.</p> <p>☉ SetAttribute () is used to set the named object in the range or specific range of the default page.</p> <p>☉ RemoveAttribute () is used to delete the default page range or the object already named.</p> <p>6. The main method of Application object:</p> <p>☉ GetAttribute (String Name) Returns the value of the properties of the name Application object specified by name.</p> <p>☉ gettributenames () Returns the name of all the properties of all Application objects.</p> <p>☉ 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> <p>☉ SetAttribute (String Name, Object Object) Sets the property value Object of the Application object specified by the name name.</p> <p>Example: Online.jsp] <% @ Page ContentType = "TEXT / HTML; Charset = GB2312"%></p> <p><body οnunlοad = "javascript: ca ZAN;">></p> <p><%</p> <p>Integer I = (Integer) Application.getaTRibute ("counter");</p> <p>String name = (string) Application.getaTRibute ("OnlineName");</p> <p>// StringBuffer Total = New StringBuffer (Name);</p> <p>%></p> <p><font color = "blue"></p> <p><% out.println ((String) session.gettribute ("UserName"));%> Hello:</p> <p></ font></p> <p><br></p> <p><font color = "red"></p> <p>Current online number: <% = i%></p> <p></ font></p> <p><br></p> <p><font color = "green"></p> <p>Online People Total: <% OUT.PRINTLN (Name);%></p> <p></ font></p> <p><script language = "javascript"></p> <p><! -</p> <p>Function Cancel () {</p> <p><%</p> <p>IF (session.getattribute ("UserName")! = "" && session.getattribute ("username")! = null) {// cancelname is the logan name</p> <p>String CancelName;</p> <p>CancelName = (string) session.getattribute ("UserName");</p> <p>//out.println (Cancelname);</p> <p>// j is the initial location of CancelName in the total roster</p> <p>// k for the total length of CancelName</p> <p>// t is the end position of CancelName in the total roster</p> <p>INT J, K, T;</p> <p>J = Name.indexof (CancelName);</p> <p>K = cancelname.length ();</p> <p>T = J K;</p> <p>//out.println(J);</p> <p>//out.println (T);</p> <p>StringBuffer Total = New StringBuffer;</p> <p>Total = Total.delete (J-4, T);</p> <p>i = new integer (I.intValue () - 1);</p> <p>Application.SetaTRibute ("Counter", i);</p> <p>Name = (string) Total.Tostring ();</p> <p>Application.setttribute ("OnlineName", Name);</p> <p>//out.println ("window.alert (" Name ") ")")</p> <p>Session.setttribute ("UserName", "");</p> <p>}</p> <p>%></p> <p>}</p> <p>-></p> <p></ script></p> <p></ body></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-11877.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="11877" 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.036</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 = 'tZtHD5HvQnX4S8824L26hGR8LYZIMq9If3lGIJD1vCWIF8bZ6Wv7aiDGWVuQMSOkoUYeJT8tIpMwVD62vI3KYw_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>