JSP Design Notes

zhaozj2021-02-16  66

JSP Design Notes

White paper sections

Introduction The Technology Prevalent Application THE Alternative Conclusion

Introduction to JSP Design Notes

Java Server Pages (JSP's) permit server side Java logic to reside within the requested document. Upon request of a JSP document the server activates the specified JSP. The JSP then becomes responsible for providing an HTML response.

The server side logic within a JSP is written in Java. The Java code segments, referred to as scriptlets, are generally responsible for providing dynamic HTML content to the JSP's response HTML. The JSP itself is compiled by the server, and is executed as an Object That Extends The Java Servlet API. AS Such, The Http Servlet Request and Response Objects Are Available By The ScriptleTs Defined Wtem, The JSP.

This document reviews client-server design considerations in respect to the use of JSP Zha. Implementation options, particularly the use of JSP language extensions and use of Enterprise Java Beans (EJB's) will also be discussed. Focus will be placed on the presentation layer and HOW THE JSP IS Used to Provide a User Interface and Communicate Business Logic Requests To The Supporting System.

If we consider a 3-tier architectural WEB application, the browser becomes the client side application. The user communicates requests to the WEB / app server via the browser. The presentation layer receives the client requests and prepares the response and server side business functionality is executed. In the context of this example, the JSP engine represents the presentation layer. It is responsible for processing requests and responses. Additional messages may be passed between this layer and that which handles business processes represented below as EJB Zha .Return to Top of Page

THE TECHNOLOGY

JSP technology uses XML -. Like tags and scriptlets They are used to encapsulate presentation logic within the JSP They can also initiate messages to distributed or server-side applications The logical separation of presentation and business logic lies in the implementation of the JSP...

Enterprise Java Beans Provide a Distinctation of Business Logic and The Remote Interfaces Provided to The EJB Client. The Use of an EJB TYPICLY FOLLOWS The Pattern:

The client application identifies itself to the server The client application uses the Java Naming Directory service to locate the desired EJB The client application retrieves a handle to the EJB Home and subsequently Remote interfaces.

The remote interface contains methods that the client is permitted to use. They represent a summary of the business logic that is implemented by the bean. The implementation logic is defined within the primary bean class. All IPC, database and resource details are restricted to the Bean class.

Return to Top of Page

Prevalent Application

Design constraints and conventions maintain the separation of presentation logic from business logic in the middle tier Prior to JSP 1.1, a JSP implementation using EJB's might have included various scriptlet sections performing EJB remote interface logic / communication.Consider the example below.:

The JSP Is Designed to Provide a Welcome Message To AN E-Commerce User. Assume The Request Included An HTML Name-Value Pair That Identified The (Pre-Registered) Customer ID.

E-commerce Site </ title> <body> <% String CustomerName; String CustomerCompany; String customerID; customerID = (String) pageContext.getRequest () getParameter ( "CustID");. Context ctx = getContext ( "some.ejb.jndi.name"); EJBHome home = (EJBHome) ctx.createHomeInterface (); EJBRemote remote = (EJBRemote) home.findCustomer (customerID); CustomerName = remote.getCustomerName (); CustomerCompany = remote.getCustomerCompany ();%> WELCOME <% = CustomerName%> We look forward to process your need, <br> <% = customercompany%> is one of our favorite companies to work with. </ Body> </ html></p> <p>The resulting JSP is a hybrid of scripting logic and html. In constructing a JSP document, the creation of the HTML base is a prudent step. It becomes the visual template that JSP scriptlets are merged into. The post execution HTML produced from the completed JSP should be that of the original HTML document. With the exception of comment, dynamically generated HTML sections and JSP content substitutions. The scripting logic, except for where desired, is completely non visual in regard to the response HTML text.</p> <p>The construction of the HTML layout conceivably begins with a Web developer. The creation of the JSP pages would be similar if not identical to the methods used to construct industry HTML pages. The next step would be the addition of JSP specific logic to identify the sections of the HTML that might be generated dynamically. This conversion step from pure HTML to JSP is where server side logic is added to the page.A completed JSP logically embodies presentation layer services and business functionality. Physically they are blended within the JSP in an as needed swapping of HTML and JSP code. Continued maintenance of the application and changes in the business logic need not affect the presentation layout. Likewise, changes in the presentation layout need not affect the scriptlet logic, it will however require that the WEB developer, not NECESSARILY A Java Programmer</p> <p>Return to Top of Page</p> <p>The alternative</p> <p>A design consideration intended to reduce the complexity of maintaining the HTML aspect of a JSP is to minimize the use of scriptlets in constructing a JSP. Custom tags, introduced in JSP 1.1, can equally produce the functionality provided by JSP scriptlets.</p> <p>Custom Tags Are Application Defined Language Extensions To Java Server Pages. Custom Tags Can Be Used WITHIN A JSP in The Following Ways:</p> <p>to produce html output to produce JSP output (JSP expressions, directives, ...) to create objects to define objects that can be seen as scripting variables within the parent JSP to iterate over a body of JSP / HTML text in a finite manner to DETERMINE IF Section of The Calling JSP Should Be Processed Or Skipped</p> <p>The goal of using custom tags to minimize the presence of scriptlets is to produce a more HTML? Like JSP. The advantages of this goal are self-evident if we consider projects that expect frequent HTML modifications. Assuming the business logic, pre-presented by the JSP tags, is stable it can be identically merged into various forms of the HTML layout, without explicitly inserting duplicate sections of scriptlet logic (Java code) .Tag handlers implement JSP custom tags. One or more tag handlers can be listed in the Tag Library Descriptor files. References to these files are included in the JSP that intends to use a given tag handler. The tag handler itself is implemented as a Java object that extends the JSP body. Upon execution it has access capabilities to the JSP's Http servlet objects IT CAN, CONCEIVABLY, PROVIDE A FULL HTML RESPONSE TO The Client in The Way That Servlets Operate. A Significant Distinction from Java Server Pages Is That Tag Handlers Are Not Designed To Be Dynamically Compiled by the Server.</p> <p>In respect to EJB's, a tag handler accesses an EJB in the same manner as the above scriptlet. It can additionally make available any object it creates, available to other tag handlers and JSP Zha. This is accomplished by the use of storage methods that operate .......... ...</p> <p>The Previous JSP Example Implement Using Custom Tags Might Appear As Follows:</p> <p><% taglib declaration; prefix = tagpre%> <html> <title> e-commerce site </ title> <body> <tagpre: lookupcustomer> Welcome <% = Customername%> We Look Forward to processing your needs. <br> <% = CustomerCompany%> is one of our favorite companies to work with. </ tagpre: lookupCustomer> </ body> </ html> As stated previously, the JSP engine and Java Server Pages logically produce presentation layer services They also provide. the interface to business services (ie EJB Zha). The physical separation of the logic associated with these middle tier components is evident in the above example. The same EJB logic in the previous example is represented here by the tag references.</p> <p>Figure 2 gives a graphical representation of the physical control flow without the use of custom tags. The client initiates execution with a JSP request. The request via URL is directed to the WEB server that is responsible for servicing such requests. The JSP request triggers the .</p> <p>Logically Identical, Figure 3 illustrate the use of tag handlers by the jsp. This is the hidden logic Implied in HTML EXAMPLE 2.</p> <p>The JSP engine, in both figures, treats the compiled JSP object as a servlet object. Figure 3 Zha tag handler object extends the JSP page body. This relationship grants tag handler access to various servlet attributes. These attributes therefore permit the tag handler to conceivably Inspect parameters passed by the client.</p> <p>Return to Top of Page</p> <p>Conclusion</p> <p>As with other tools of the trade, innovations and nuances to existing tools do not invalidate existing design methodologies. They do however provide new versatility and the expansion of possibilities with regard to application design.Custom tag extensions, in contrast to standard tags, provide the application builder the ability to define custom tags to satisfy some functionality not provided by the standard API. to benefit by using tag extensions to reduce the amount of Java functionality that the JSP API provides, might seem oxymorinic, and it is. With the exception of .</p> <p>While a server side application designer does not typically consider the cosmetic aspect of implementing source code, JSP source code might prove to be the exception. It does after all suggest the strong possibility that a Web / HTML developer perform the continued maintenance of the HTML portion Of the JSP. this is a role, of course, traditional allied with client side responsibilities.</p> <p>The nuances introduced by JSP custom tags present nuances in the maintenance of JSP Zha. The arguments presented here presume that the HTML produced by the JSP Zha in discussion are non-trivial HTML documents, although non-complex HTML documents may benefit from similar design considerations .</p> <p>~ End of Aurora Information Systems' White Paper Series # 9 "JSP Design Notes" ~</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-17605.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="17605" 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.037</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 = 'E1WEYCKe_2FOhELMRzZKY1UtIsTF_2Fv0YLjZGv54d6vUpbQONzl9HmHk13MusXo6KIrRMgOBO9NtdGKLunThmgQfQ_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>