Classic entry tutorial: JSP standard template library (on)

zhaozj2021-02-16  42

Classic entry tutorial: JSP standard template library (on)

Introduction

JSP Standard Template (JSTL) is a new component developed by Sun. JSTL allows you to use the label (Tags) to develop JSP page, rather than using most JSP programmers have been habitually developed. JSTL can almost anything to do with traditional JSP Scriptlet code. You may be confused, why do we need another such HTML to generate language? STL allows JSP programmers to program with Tags instead of Java code. To show this is more superior, an example will be given below. We will check a very simple JSP page from 1 to 10. We will check two ways, one is based on JSP-based scripTlet, one is JSTL. When the example of this counter page is written with JSP scripTlet, the JSP page is as follows: count to 10 in jsp scriptlet </ title> </ head> <body> <% for ( INT i = 1; i <= 10; i ) {%> <% = i%> <%}%> </ body> </ html> as seen in the above example In that, the page source code generated using the Scriptlet code will contain a mixed HTML tag and Java statement. This hybrid programming method is not the best way, and the main reasons have the following points. The main reason is its readability. This readability is mainly based on humans and computers. JSTL allows programmers to view a page that contains only a full HTML and a tag similar to HTML. The readability of the SP Scriptlet code is not suitable for humans. This mixed scripTlet and HTML code are also difficult to read for your computer. Especially for those HTML official tools such as Dreamweaver and Microsoft FrontPage, it is more prominent. Currently, most HTML official tools isolate the JSP Scriptlet code in the form of non-editable blocks. This HTML official tool usually cannot directly modify the JSP Scriptlet code. The following code shows how this counter example is written in a JSTL method. As you can see, this code list is unchanged, just a label is used. HTML and JSTL tags are mixed to produce this program. <% @ Taglib URI = "http://java.sun.com/jstl/core" prefix = "c"%> <html> <head> <title> count to 10 example (useing jstl) </ title> < / head> <body> <c: foreach var = "i" begin = "1" end = "10" step = "1"> <c: out value = "$ {i}" /> <br /> < / c: foreach> </ body> </ html> When you check the code above this example, you will see that the JSP page contains only tags. The above code uses an HTML tag such as <HEAD> and <br>. This label usage is not limited to HTML tags. This code can also use a JSTL tag such as <C: Foreach> and <C: Out>.</p> <p>In this article, some JSTL foundations will be described. Installing JSTL To use JSTL, you must have a JSP1.2 (or higher) container. The most common JSP container is Apache Tomcat. You can download from http://jakarta.apache.org/tomcat/ here. Independent Tomcat allows you to use regular JSP scripTlet code. To use JSTL, you must install JSTL in Tomcat. JSTL's main URL is http://java.sun.com/products/jsp/jstl/. To use JSTL, you must decompress this file and install it to the correct position of Tomcat. To install JSTL in Tomcat, there are three steps below:</p> <p>Copy the JSTL JAR file to the lib directory of Tomcat. If you use Windows, then the most likely location of the lib directory is C: / program files / apache tomcat 4.0 / webapps / root / web-inf / lib. You should copy these JAR packages to your Tomcat jar directory. Copy the JSTL TLD file to Tomcat's Web-Inf directory you check the JSTL release file, you should notice that 8 files are tailing with a TLD extension. All these 8 files should be copied into your web-inf directory. Modify the web.xml file contains these TLD files. Finally, you must modify your web.xml, add 8 label libraries (entry). The entry that needs to be added is as follows: <taglib> <taglib-uri> http://java.sun.com/jstl/fmt </ taglib-uri> <taglib-location> /web-inf/fmt.tld < / taglib-location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/fmt-rt </ taglib-uri> <taglib-location> / web-inf / fmt- Rt.TLD </ taglib-location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/core </ taglib-uri> <taglib-location> / web-inf / C.TLD </ taglib-location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/core-rt </ taglib-uri> <taglib-location> / web- INF / C-RT.TLD </ Taglib-Location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/sql </ taglib-uri> <taglib-location> / Web-inf / sql.tld </ taglib-location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/sql-rt </ taglib-uri> <taglib-location > /Web-inf/sql-rt.TLD </ taglib-location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/x </ taglib-uri> <taglib -location> /web-inf/x.tld </ taglib-location> </ taglib> <taglib> <taglib-uri> http://java.sun.com/jstl/x-rt </ taglib-uri > <Taglib-location> /web-inf/x-rt.tld </ taglib-location> </ taglib> After completing these three steps, you can now prepare to test your JSTL installation.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-24915.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="24915" 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.038</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 = 'oB5uSHUyQ_2FYG1faFofkCfiyfHzVFhO5HvmcXfpyvem_2BHWUPGOHkD0PvYc51m_2FcUkCr23AgAtrxXPWzUQlL9g7Q_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>