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.
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.
The JSP page corresponding to the HTML fragment shown in Listing 2 is similar to the example in Listing 3.
Listing 3. A JSP page that uses data containing data
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.
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.
Listing 4. Insert Java code in the tag language page
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.
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.
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.
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.)
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.
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.
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.
<% // 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 () ;%>
<% = actor.getlastname ()%> th>
<% = 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 ), which interprets the code snippet in the tag library at runtime.
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
table> center>
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.
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.)
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.
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.
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.
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.
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, Mark must be converted to 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.
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.
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.
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.
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.
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.
Have fun, see it online!
Reference
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.