Spring Framework Tag Library Beginner Guide

zhaozj2021-02-16  130

Spring is an Application Framework that serves all levels: provides the BEAN configuration foundation, AOP support, JDBC's extraction framework, abstract transaction support, and so on. It has a very significant feature: at a level if you don't need Spring support, you can use the string Class, only the features of some part of it. From its design concept, you can see String Help you implement the true logical layer and the WEB layer separation. For EJB, Spring is a lightweight J2EE application development framework. The lightweight referred to here is the Spring framework itself, not that Spring can only apply to lightweight application development. Spring's lightweight is reflected in its frame itself, and the support and assembly capabilities of other application tools, Spring makes us reduce the risk between the technical levels compared to EJB's homonomer. EJB has strong cohesiveness, such as data persistence layer management, transaction management, and lifecycle management are all handed over to the management of the EJB container. The white box characteristics of the cohesiveness allows us to give up a part of the controllability to trust the container capacity. . Spring is considering how "not built wheels", how to better assemble these wheels, let them turn better. For example, data persistence layer management can use Hibernate, log management can use JakartacomMonLogging. A more appropriate metaphor is "We have to get a few nails. In order to accomplish this, the hammer producer produces a large and small series of hammers, each with a complex method of use, used to nail a special Nail, the result makes us headache. Solve the problem of excessive hammer, through Spring, we can use several hammers, but it is like only one hammer. " (Note: This paragraph is visible online. Here is this metaphor. I personally feel very vivid) There are also some simple summary on this framework: "Spring has several major parts: bean ApplicationContext, with a unified , IoC's way, manage, assemble, use the system components, replace all plants; persistence framework; web framework. "J2EE Framework" is the vision of Rodjohnson, he hopes that Spring provides the top to the J2EE lightweight solution The comprehensive infrastructure support. "The above is a brief introduction to a new Framework, it is said to be the direction of J2EE development. Previously on the discussion of J2EE's best combination, I heard that this JSTL STRUTS (or webwork) Spring Hibernate is very optimistic. If you are interested, you can go to the Springframework Chinese Forum. The topic of this article is transferred below. Spring tag library introduction and usage: This article will focus on the tag library provided by Spring and its usage: When you use Spring Framework in the project, the performance layer can select the Spring Framework's own tag library. Of course, this is not your only choice. You can choose other tag libraries or template replacement techniques. Spring Framework does not provide a very rich tag library for applications. The marker library provided by Spring Framework is just to use it, it is not unpacking. Oh, this is different from the Struts rich tag library. In fact, this is in line with the starting point of Rodjohnson, which is both "no wheel". Of course, the Spring Framework tag library has its own characteristics, it can be said to be a good supplement.

The Spring tag library is classified as follows: 1, Spring: HasbinderRors 2, Spring: Bind 3, Spring: Transform 4, Spring: Message 5, Spring: HTMLESCAPE 6, Spring: Theme Let's take a specific introduction: 1, Spring: HasbinderRors Org.springframework.Web.Servlet.tags.binderrorstag tag library processing class. This tag provides an Errors for binding objects. If this tag is used, the error on this object will be displayed on the page. The prerequisite for using this tag is to use the tag, and this tag cannot be used to represent the status of the object, which can only bind the object itself and the object of the object. The specific usage is as follows: please fix all errors! Through this simple example, I will tell the properties of this tag. Name: It is the name of the bean to be checked. This attribute is required. Here is a simple usage, so it does not introduce the Errors variable it contains. Specific English documents. Same. 2, Spring: BIND corresponds to the org.springframework.web.servlet.tags.bindtag tag library processing class This tag is used to assign a value for a bean or bean, usually with Form, which is equivalent to the action of an action. It indicates that the form is to be submitted to the attribute of that class or class. Where the Path property is a must, specify the path to the class. For example:

increase (%): > < / TR>
...................... 省 省 3, Spring: Transform corresponds to org.springframework.web.servlet.tags.transformTag tag library processing class, this tag is used to convert In the form, it is not possible with the attributes of the attribute in the table, usually and . Marks to Using better support. The properties are as follows: value: It is necessary. And the BEAN class that is pointed to the current tag. It is the entity class name you want to convert. Var: not required. This string is used to bind the output to page, request, session or Application Scope. Output to JSP. SCOPE: Not required. Prerequisites VAR must be set. Its value can be Page, Request, Session or Application. 4, Spring: Message corresponds to org.springframework.Web. Servlet.Tags.MessageTag Tag Library Test Class This tag is used to help SpringFramework supports internationalization. It is similar to JSTL's FMT: Message tag. Of course, this tag can work a native SpringFramework framework. The property is as follows: Code: not required Used to find Message, if it is not used, Text Will be used. TEXT: It is not required. If Code does not exist, the default is the text output. When both Code and Text are set, the tag will output to null. Var: It is not required. This string is used to bind output results to page, request, session, or Application Scope. The default is output to JSP.

Scope: It is not required. Prerequisites VAR must be set. Its value can be Page, Request, Session, or Application. 5, Spring: htmlescape corresponds to org.springframework.web.servlet.tags.htmlescapeTag tag library processing class is not common, omitted 6, Spring: Theme corresponds to org.springframework.Web.Servlet.Tags.Themetag tag library processing class is not common, Let us look at a specific example after you have finished learning these usage. The configuration steps are as follows: Directory Structure Figure: -spirngapp -Web-Inf -Classes -Lib -Src -war 1, copy Spring.TLD to the web-INF directory.

2, copy Spring.jar to the web-INF / lib package as follows: Configure the taglib property in web.xml, the code is as follows: < Servlet> springapp org.springframework.web.servlet.dispatcherservlet 1 SpringApp *. Htm index.jsp / Spring /web-inf/spring.tld < / taglib-location> JSP page code as follows: <% @ include file = "/ web-inf / jsp / include.jsp"%> <% @ taglib prefix = "Spring" URI = "/ Spring"%> <fmt: message key = "title" /> </ title> <fmt: message key = "PriceIncrease. Heading "/> </ h1> <form method =" post "> <Table width =" 95% "</p> <p>BGColor = "F8F</p> <p>8FF "border =" 0 "cellspacing =" 0 "cellpadding =" 5 "> <tr> <TD alignment =" right "width =" 20% "> increase (%): </ td> <spring: bind path = "PriceInCrease.Percentage"> <TD width = "20%> <input type =" name = "percentage" value = "<c: out value =" $ {status.value} "/>> </ TD> <TD Width = "60%> <font color =" red "> <c: out value =" $ {status.errorMessage} "/> </ font> </ td> </ spring: bind> < / tr> </ table> <br> <spring: hasBindErrors name = "priceIncrease"> <b> Please fix all errors </ b> </ spring:! hasBindErrors> <br> <br> <input type = "submit "alignment =" center "value =" execute "> </ form> <a href="<c:URL value="hello.htm">> Home </a> </ body> </ html> < Spring: bind> tags are often used to bind <input> form elements to submit to PriceInCrease.java, in fact, PriceInCrease.java is a class containing some getter and setter. When the user presses the button, its form is The value is actually placed in PriceIncrease.java by Framework. <Spring: Bind> is often used with Form. This $ {status.ErrorMessage} and $ {status.value} are special variables defined by Framework, they are used To display the error information and the data in the current form. Oh, today, let's see you, please refer to its documentation.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-8235.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="8235" 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.056</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 = '2_2FH_2FzJHQj9OZwohEs27eZLqI0c35Q3R0uHTBlhWP_2FKpE8t5sPcl06A9Ne0WDcywLiEk_2FSFRu2p6OHar6hROy_2Bw_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>