JSTL Getting Started (Continued 1)

xiaoxiao2021-03-06  88

FILE Name: ImplicitObjectScope.jsp <% @ page contenttype = "text / html; charset = GBK"%> <% @ Taglib URI = "http://java.sun.com/jstl/core" prefix = "c"% > ImplicitObjectScope </ title> </ head> <body bgcolor = "# ffffff"> <h3> ImplicitObjectScope.jsp </ h3> <p> <strong> First set the scope of action is the four variables of Application / Session / Request / Page, respectively </ Strong> </ P> <C : set var = "ApplicationVar" Value = "ApplicationVarvalue" Scope = "Application" /> <c: set var = "sessionvar" value = "sessionvarvalue" scope = "session" /> <c: set var = "requestvar" Value = "Requestvarvalue" Scope = "Request" /> <c: set var = "pagevar" value = "page" /> <% // with equivalent /*session.setttribute ("sessionvar "," sessionVarValue "); application.setAttribute (" applicationVar "," applicationVarValue "); request.setAttribute (" requestVar "," requestVarValue "); pageContext.setAttribute (" pageVar "," pageVarValue "); * /%> session variable value : <c: out value = "$ {sessionscope.sessionvar}" default = "there is not sessio N variable "/> <br> Application Variable Value: <c: out value =" $ {applicationscope.Applicationvar} "> There is not application variable" </ c: out> <br /> Request Variable value: <c : Out value = "$ {requestscope.requestvar}"></p> <p>There is not request variable </ c: out> <br /> Page Variable value: <c: out value = "$ {pagescope.pagevar}> There is not page variable </ c: out> <p> <form action = "ImplicitObjectScope.jsp" method = "post"> <input type = "hidden" name = "requestName" value = "this is the value of requestName" /> <input type = "hidden" name = "isForward" value = "Y" /> <input type = "Submit" Value = "Click here to submit to this page and forward the request to the ImplicitObjectScope1 page" /> </ form> <form action = "iMPlicitObjectScope.jsp" Method = " POST "> <input type =" hidden "name =" requestname "value =" this is the value of requiredname "/> <input type =" hidden "name =" isforward "value =" y "/> <input type = "hidden" name = "isforward" value = "y" /> <input type = "submit" value = "Click here to submit to this page, and forward the request to the ImplicitObjectScope1 page, and forward the request to the Destofforward page" /> </ form> <form action = "implicitObjectscope1.jsp" method = "post"> <input type = "hidden" name = "requestname" value = "this is the value of requiredname" /> <input type = " Submit "Value =" Click here to submit them directly to the ImplicitObjectScope1 page "/> </ form> <form action =" iMPlicitObjectScope1.jsp "Method =" post "> <input type =" hidden "name =" requestname "value =" this is the value of requestname "/> <input type =" hidden "name ="</p> <p>IsforWaragain "value =" y "/> <input type =" Submit "value =" Click here, directly to the ImplicitObjectScope1 page, then forward the request to the Destofforward page "/> </ form> </ p> <C: If test = "$ {NOT EMPTY param.isforward}> <jsp: forward page =" ImplicitObjectscope1.jsp "/> </ c: if> <p> below is an example of implementing accumulation using the Foreach tag (EL combined Javabean use).</p> <p></ p> <c: set value = "0" var = "count"> </ c: set> <table border = "1"> <tr> <td> index </ td> <TD> Number </ TD> <TD> SUM </ TD> </ TR> <c: foreach items = "$ {SimpleBean.Numberlist}" var = "number" varstatus = "status"> <tr> <td> <c: Out value = "$ {status.index}" /> </ td> <td> <c: out value = "$ {number}" /> <c: set var = "count2" value = "$ {count}" / > <C: set var = "count" value = "$ {count2 number}" /> <c: out value = "$ {count}" /> </ td> < / TR> </ c: foreach> </ body> </ html> file name: ImplicitObjectScope1.jsp <% @ page contenttype = "text / html; charset = GBK"%> <% @ Taglib URI = "http: / /java.sun.com/jstl/core "prefix =" c "%> <jsp: usebean id =" simplebean "scope =" request "class =" jsptag.simplebean> </ jsp: usebean> <jsp: setProperty Name = "SimpleBean" Property = "*" /> <c: if test = "$ {not empty param.isforwaragain}> <jsp: forward page =" destofforward.jsp "/> </ c: if> <html > <head> <title> ImplicitObjectScope1 </ title> </ head> <body bgcolor = "# fff"> <h3> implicitObjectscope1.jsp </ h3> <p> Note the variable of different scope, its value is Variation </ P> <p> session variable value: <c: out value = $ {sessionscop E.SESSIONVAR} "Default =" There is not session variable "/> <br /> Application Variable Value: <c: out value ="</p> <p>$ {ApplicationsCope.ApplicationVar} "> There is not application variable" </ c: out> <br /> Request Variable value: <c: out value = "$ {requestscope.requestvar}> There is not request variable </ C: Out> <br /> Page Variable value: <c: out value = "$ {pagescope.pagevar}> There is not page variable </ c: out> </ p> <p> as follows, combined with EL JavaBean example: <br /> Output value of reviewname: <c: out value = "$ {simplebean.requestname}> The SimpleBean.RequestName is not existed. </ C: OUT> </ P> </ table> </ body> </ html> file name: destofforward.jsp <% @ page contentty = "text / html; charSet = GBK"%> <% @ Taglib URI = "http://java.sun.com/jstl/ CORE "prefix =" c "%> <jsp: usebean id =" simplebean "scope =" page "class =" jsptag.simplebean "/> <% - trying to change Scope to Request -%> <% - jsp: usebean id = "simplebean" scope = "page" class = "jsptag.simplebean" / -%> <html> <head> <title> destofforward </ title> </ head> <body bgcolor = "# ffffffff"> <h3> destofforward.jsp </ h3> <p> CAUTION Compare the change here <br /> Request variable: <strong> <c: out value = "$ {requestscope.requestvar}" > There is not request variable </ c: OUT > </ strong> </ p> <br /> Output Value of ReqEutname: <strong> <c: out value = "$ {simplebean.requestname}> The SimpleBean.RequestName is not existed. </ c: out> </ strong> <br /> <p> Note: Here, JavaBean's scope is Page, which is different from the previous page, so output is not present.</p> <p></ p> </ body> </ html> file name: SimpleBean.javaPackage jsptag; / ** * <p> Title: </ p> * <p> Description: a Simple Java Bean </ P> * <P > Copyright: Copyright (c) 2004 </ p> * <p> Company: </ p> * @Author zqy * @version 1.0 * / import java.util.arrayList; public class simplebean {</p> <p>PRIVATE STRING RequestName = null; private arraylist numberlist = new arraylist ();</p> <p>Public SimpleBean () {for (int i = 1; i <= 10; i ) this.numberlist.add (String.Valueof (i));}</p> <p>Public void setRequestName (String RequestName) {this.RequestName = RequestName;}</p> <p>Public String getRequestName () {return this.RequestName;}</p> <p>Public void setNumberlist (arraylist numberlist) {this.numberlist = numberList;</p> <p>public ArrayList getNumberList () {return this.numberList;}} complement: how to distinguish the following passage on page scope and request scope: "Objects are created within a JSP page instance that is responding to a request object There are several scopes:. page - Objects with page scope are accessible only within the page where they are created All references to such an object shall be released after the response is sent back to the client from the JSP page or the request is forwarded somewhere else References to objects.. with page scope are stored in the pageContext object request -. Objects with request scope are accessible from pages processing the same request where they were created References to the object shall be re-leased after the request is processed in particular, if the request.. IS Forwarded to a resource in The Same Runtime, The Object Is Still Reachable. References To Objects with Request Scope Are Stored In The Request Object.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-95550.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="95550" 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.039</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 = 'iyzI4zUQt_2BCyWLy39L7zgW_2Bs_2FFHYowrJrxizZkcIfSO08MQno8KjfxqZf89_2FmQRVXWtp0EqmfXvgDaoI'; 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>