Criticism looks like a feasible expression technology: JavaServerPages Servlet technology (below)

zhaozj2021-02-08  468

JSP technology promises now, let's discuss the specific content of JSP coding. JSP technology is committed to providing designers and developers to provide the most appropriate representations they need. JSP technology is part of the J2EE platform, which shows the most powerful support for Sun Corporation to give Java products. In order to make you have a concept of this solution, you can try to search for "JSP" on Amazon.com, you will find that the books of JSP are more than the books of other Java APIs. . Before I discuss the specific issues of JSP technology, you need to have a clear understanding of its commitment.

Content and representation First, JSP technology is used to separate content and representation, this is earliest to appear in a series of targets published by the JSP. In fact, JSP design is directly for developers complaining, these developers are repeatedly turned out to Out.Println (" " PageInfo.gettitle () "</ TITLE>" </ Head> ") is bored. This hardcoded content and mixing of the runtime variable have caused a huge burden on the servlet developers, but also difficult developers are difficult to turn over even minimal changes to the representation.</p> <p>JSP technology changes this situation by supporting normal HTML pages (and later WML or other tag language page). It is actually imitating out.println () statements without developers write code. It also allows the variables to be inserted into the page until these variables are explained.</p> <p>The JSP page corresponding to the HTML fragment shown in Listing 2 is similar to the example in Listing 3.</p> <p>Listing 3. A JSP page that uses data containing data</p> <p><% @ page import = "com.ibm.display.pageutils"%> <% @ page import = "com.ibm.display.pageInfo"%> <% pageinfo pageinfo = (pageinfo) session.gettribute ("Page_Data") %> <Html> <head> <title> <% = pageinfo.gettitle ()%> </ title> </ head> <body> <! - Other HTML content -> </ body> </ html></p> <p>According to these initial principles, JSP technology (at least in its declaration design) will satisfy the first principle of the representation, as described above: that is, the separation of content and representation.</p> <p>The second feature listed in the code and tag JSP technology may cause your attention, that is, JSP encoding allows the Java code to be inserted directly into the tag page. In order to understand the reason for this decision, we recall the situation when developing JSP specifications. Sun and Microsoft's competition has been very intense, mainly from Microsoft Active Server Pages (ASP). JavaServer Pages are similar to the name of Active Server Pages. Moreover, multiple characteristics of the ASP seem to be intentionally. So the JSP author chooses to join the Java code in their tag. As an example of joining Java code in the mark, the JSP segment in Listing 4 automatically adds rows to display each item in the actor vector.</p> <p>Listing 4. Insert Java code in the tag language page</p> <p><% @ page import = "com.ibm.display.pageutils"%> <% @ page import = "com.ibm.display.pageinfo"%> <% @ page import = "com.ibm.people.actor"% > <% @ page import = "java.util.Iterator"%> <% @ page import = "java.util.Vector"%> <% pageinfo pageinfo = (pageInfo) session.getattribute ("Page_Data") Vector Actors = PageInfo.getactors ()%> <html> <head> <title> <% = pageinfo.gettitle ()%> </ title> </ head> <body> <h2 align = "center"> search results: actor < / H2> <center> <hr width = "85%"> <table width = "50%" cellpadding = "3" cellspacing = "3" border = "1" bgcolor = "# fffcc"> <% for (Iterator i = actors.iterator (); I.hasNext ()) {actor = (actor) i.next ();%> <tr bgcolor = "# ffcccc"> <th width = "50%" align = "center "> <% = Actor.getlastname ()%> </ th> <trh width =" 50% "align =" center "> <% = actor.getfirstname ()%> </ tH> </ tr> <% }%> </ Table> </ center> </ body> </ html></p> <p>Remember, so far, I am the initial goal of designing JSP technology. In the following chapters, I will make my judgment of this goal when I talk about the issue of JSP technology. However, you may have a bit doubtful because embedding code to the JSP page seems to result in a problem associated with the first goal of JSP technology (ie, separate the content and representation). But actually (ace cough), I have not commented.</p> <p>Designers and developers JSP technology is worth mentioning (also worthy of appreciation) the goal is that it tries to establish a clearly defined role during application development. Separation of content and representation on the surface, JSP technology has defined a more obvious boundary between designers and developers. Designers use only standard HTML, WML, or other suitable language to create tags, developers write code. Of course, many designers have learned JavaScript, so it is not surprised that many of them also start learning JSP coding. In many cases, they are not just pure tags, but write a complete JSP page and hand it over to developers. After regular adjustment, the developer places these JSP pages as the front end of a part of the overall application to the appropriate position. But the key is that many designers do not include JSP, so they have work in this environment. I have clearly illustrated a good representation of things that should be provided, as well as specific issues that JSP techniques try to solve. Now, I am ready to cut the topic: JSP technology design although the idea is very good, it brings a lot of questions. Before you choose to use JSP in your application (you may still use), you should know at least the possible defects.</p> <p>You should also understand a small problem that J2EE programming platforms often overlooked: This platform provides an API does not mean you must use it. Just like this sentence, it is a bit stupid. Many developers are still struggling in JSP, EJB or JMS API. They think that if they do not use these APIs, their applications are unlike a true "J2EE application". In fact, many APIs promised to this platform are unnecessary to most applications. If you have problems with JSP technology or have doubts about it, you can do not use it! Please take a closer look at its advantages and disadvantages before choosing JSP technology in your application. Now let's take a look at it.</p> <p>Portability and language locking JSP technology locks you in a specific language. It should not be seen too much for this point. When designing an enterprise application, Java technology is the only language selection (at least my point of view). On this issue, there is no solution to the language. Of course, in this stage of the game, I still don't consider the smoke cigarette and the actual situation of the Microsoft .NET platform. Only time will prove whether the Microsoft .NET platform will develop into a virtually independent product. (I am very doubtful.)</p> <p>Also, choose JSP technology to force you to use Java language, at least in this regard. Although CORBA can be used for business logic, JSP coding does need to be familiar with some servlets and core Java languages. This is usually not a problem because many developers turn to JSP programming from the J2EE platform.</p> <p>Mixing and independence in full text, I mentioned the idea of ​​the content and indicating the content and expressed separately. You may have been annoyed, so now we have to determine if JSP really realizes this goal. As I have said, since JSP claims to be designed for this separation goal, should we assume that it achieves this goal? right? not necessarily.</p> <p>The boundary JSP between the content and the representation allows the Java code to be inserted into the tag language page, which is quite dangerous, and it even allows the content to be mixed into the representation. Worse, business logic often mix into the JSP page, as shown in Listing 5.</p> <p>Listing 5. JSP page containing business logic</p> <p><% @ page import = "com.ibm.display.pageutils"%> <% @ page import = "com.ibm.display.pageInfo"%> <% @ page import = "com.ibm.logic.adminutils"% > <% @ page import = "com.ibm.people.actor"%> <% @ page import = "java.util.Iitrator"%> <% @ page import = "java.util.Vector"%> <% PageInfo PageInfo = (PageInfo) Session.gettribute ("Page_Data")%> <html> <head> <title> <% = pageinfo.gettitle ()%> </ title> </ head> <body> <h2 align = "center"> Search Results: actor </ h2> <center> <hr width = "85%"> <Table width = "50%" cellpadding = "3" cellspacing = "3" border = "1" bgcolor = " #Fffccc "> <% // Perform different search (business logic!) Vector (). Haspermission (" administrator ") {actors = adminutils (" administrator ") {actors = adminutils. getActors ());} else {actors = pageinfo.getactors ();} for (iTerator i = actors.ITERATOR (); i.hasnext ()) {actor c a = (actor) i.next () ;%> <Tr bgcolor = "# ffcccc"> <trh width = "50%" align = "center"> <% = actor.getlastname ()%> </ th> <th width = "50%" align = Center > <% = Actor.getfirstname ()%> </ t> </ tr> <%}%> </ table> </ center> </ body> </ html> JSP supporter will tell you the JSP tag The library can help you avoid this problem. The tag library allows a customized tag to JSP pages (such as <authors />), which interprets the code snippet in the tag library at runtime.</p> <p>The use of custom markers and related tag libraries will make the above examples into the code in Listing 6. Listing 6. Binding to custom tags and tag libraries</p> <p><Center> <Table Width = "50%" cellpadding = "3" cellspacing = "3" border = "1" bgcolor = "# fffcc"> <actors /> </ table> </ center></p> <p>At runtime, the code of this tag will execute, the correct result is inserted into the page. But this did not solve the problem. At this time, the argument for JSP technology is not to indicate whether the content can be separated, but whether they must be separated. As long as the JSP programming allows the embedded code, it is easy to use the embedded code to make the final modification (especially when the deadline is neighboring), not the code is converted to the tag library. If this is not the case, consider the rapid speed of the Java language exceed C and C : Java does not allow many problems in C, such as pointer addition. Although you can always argue in C, it is not necessary to perform a pointer plus, or excellent programmers never insert the code scripTlet, but we all know what the actual situation will be. Java language is better than C because it prohibits this bad habit. But in this case, JSP is extremely similar to the C language, which allows some bad habits.</p> <p>Regarding whether JSP technology has reached the target it claims, there is also a test standard, which is to see if it can actually reach the goal. Of course, JSP is unfair with unlike criteria. Most template engines (such as FreeMarker and Webmacro have this same embedded code feature, usually these templates use language similar to Perl. However, such embedded code is not allowed like ENHYDRA's XMLC. These techniques use a pure tag language page instead of input and generate a Java method. This approach is essentially changing the program stream, not the page (JSP technology) to call the application's logic, the application (Enhydra) use method to affect the value in the page. In the specific case of ENHYDRA, XMLC converts the page into a DOM tree and uses the DOM's HTML binding to allow "domain" in the page. (For more information on ENHYDRA XMLC, see Resources.)</p> <p>At this point, JSP is more serious than XMLC issues. For example, although JSP technology enables its goal, it only allows the tag library. However, the total trend in the Sun specification is always compatible backwards, or at least a long period of time. The current version of JSP 1.1 allows you to use Scriptlet, so it is estimated that the JSP page contains this situation to maintain a few years. Before discussing JSP coding, note that it actually provides the product (which is much more than the pseudo-separation between the user interface and the code of the driver application) and its goals (ie, completely separated content and representation) are still quite Big gap.</p> <p>Single processing and multitasking are discussed above, ideally, designers should only perform single processing, that is, graphical design work, developers should only focus on encoding. In this way, the designer should be able to modify it after a page translates into the format used by the application. In the case of a JSP page, this should be imported into the JavaBean, insert embedded code, and add a custom tag library to the page. The problem is that some designers use HTML editors such as HotMetal, Macromedia Dreamweaver or FrontPage, which cannot identify code scriptlets or tag libraries, means that designers have only received some pages. It can be imagined when the tag library or code segment generates tables in table or other formats. Using an incompatible HTML editor, the designer can't see what the elements look like. JSP coding is not to distinguish between different roles in different roles, but the developer must be able to complete a variety of tasks to become a developer and designer. And bear other roles. Does this important feature not convincing? Then you can download the J2EE reference implementation and transfer any one of the included JSP pages into the HTML editor you came, such as Dreamweaver. This page is immediately filled with yellow zones so that you know all the "illegal" tags included in the page. Of course, the yellow area is caused by JSP tags and code, not any actual errors in the page.</p> <p>So far, there is no editor that can support JSP, I have not heard that some people are working on developing such editor. The template engine also has this same problem, many Java-based programs (such as I like ENHYDRA), allows the tag pages to be submitted to represent technology. In this case, the designer can repeatedly modify the tag page and re-submit them back. The engine or compiler running representation technology can convert this page to the correct format and do not need to change the code (in general). The result is what we hope: designers are designers, and developers are developers.</p> <p>Therefore, compared to the actual functionality provided by JSP technology, I hope you must carefully treat JSP technology proposed commitment. In fact, in order to successfully run in an JSP technology-driven environment, you must have your developer to handle a large number of tags, or learn at least some JSP programming.</p> <p>One of the most serious flaws of HTML and XMLJSP technology is also the most easily ignored, that is, it is not compatible with XML. More accurately, especially in the HTML field, JSP page does not need to be compatible with XHTML. XHTML is a World Wide Web Alliance (W3C) specification, which is now replacing HTML 4.0. XHTML defines an HTML tag set according to a structure complete XML document. For example, <br> Mark must be converted to <br /> to ensure compliance with XML regulations. (If you feel that this is not clear, you can check the XML specification and developerWorks About XHTML articles, which are listed in the reference.) Image tags also have similar rules, in XHTML 1.1 (recently born), most digital Properties and other styles are transferred to the CSS style sheet. In addition, most standard HTML documents can be easily converted to XHTML 1.0, which means they can easily read the XML-compatible analysis program, such as Apache Xerces, and can be controlled in XML.</p> <p>You will ask: "What is the most important thing?" The most important thing is that XML quickly became the global standard of Internet and intranet. For any other applications that use the basic XML data processing tool, data is transmitted in XML format, which can easily use the data of your application. Imagine that it is necessary to convert the data into the XML format to communicate with the credit card company! In many cases, your data representation also needs to exchange data with other companies. The most common situation is the portal site application that receives content from different providers (such as weather, stock quotes, news, etc.), which often have markers with providers. However, JSP pages cannot work well in such an environment due to mixing the code and custom tag library. The JSP page is hardly the complete XML document, and it is not necessary to inform XHTML. Because XHTML is a tag language, it does not allow various JSP custom tag libraries. But more importantly, the code snippet inserted into the JSP page is not any form of tag, and once there is another application handles them, the burden of the analysis program is generated.</p> <p>Let me talk about the whole story before you comment on me. If the application allows the original client to calculate the value of the JSP page, the result is pure HTML (or WML, VOXML, etc.). However, most applications for requesting data use certain forms of cache because the round trip on the network is expensive. In these cases, the cached page returns to the old data. In this case, you may want to return the results of the pure XML in all, preferably a static form. But JSP technology is in powerless. The JSP page must always be evaluated at runtime, so you can remove the JSP code scripTlet and tag library.</p> <p>Test: Do you have other expressions to complete this task? The answer is yes. The absolute leader in this area is an Apache Cocoon project, which is completely XML based on XML, which is a XSLT style table application (that is, it can be applied at runtime, or still applied). Since the XML Server Pages are actually an XML document, they are always in accordance with XML. Other techniques that allow pure tag language page entered (eg Tea and Enhydra XMLC) can also allow this, although they don't force this. In these cases, users can use XHTML or standard HTML. But this is still better than JSP, because the format complete XML cannot be static in JSP.</p> <p>Summary I hope that I will broaden some of my eyes for you so that you have seen the advantages and disadvantages of JSP technology. Now you can view JSP program as an optional technique in a variety of representations. At this point, you may have doubts about the overall J2EE programming model. Now you may want to further study alternatives to this platform and select an alternative JSP encoding in Apache Cocoon, Enhydra, and multiple templates.</p> <p>Finally, it should be remembered that although this article seems to be opposed, it is not recommended to use or not use JSP. I have no intention to encourage you to deeply explore whether it meets your requirements. The programming model is like an example, sometimes it is, it is time to do. Think twice, find the most suitable for your program and make decisions, this total is better than the grass rate.</p> <p>Have fun, see it online!</p> <p>Reference</p> <p>See the current JSP specification to get all content. Further review the new content in JSP1.2. Is worried about XML compatibility? You can read specifications and Molly Holzschlag articles Article for DeveloperWorks on Getting Up to Speed ​​to get the details of XHTML. The XML view of the style document is obtained on the W3C Style Center. Need to know the J2EE scheme than providing more features of JSP? Is it an open source code? Please read today's enhydra. Libe your thoughts, look at Apache Cocoon, which is an alternative to another open source using the XSLT to handle the dynamic directory. If you don't mind jump out of Java, the template engine can save you! Two dedicated sites are WebMacro and FreeMarker. About the author Brett McLaghlin is the ENHYDRA strategist of Lutris Technologies, specializing in distributed system systems. He is the author of Java and XML (O'Reilly); engaged in Java Servlet, Enterprise JavaBeans, XML, and businesses to enterprises. Jaason Hunter has created a JASON Hunter, which provides a simple API for manipulating XML from Java Applications. He is still an Apache Cocoon project, an active developer of the EJBoss EJB server, and is one of the founders of the Apache Turbin project. You can contact Brettt to Brett@newinstance.com.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-472.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="472" 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.064</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 = 'uWRfqCCucmrUt4x5oFcDo3mpFcZB2XaLSHMYv4CaLrneUVC0bsneN9JISQckVRjR0jkBnXIj8LXh9P_2Ba'; 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>