As a senior technical experts and the Enhydra Java supporters, the author strongly recommends that developers in the choice of Web application programming language, use of other alternative to JavaServer Pages (JSP) servlets technology. JSP technology is Sun's J2EE platform and programming model as part of the content used to solve the monotonous appearance of the beautiful into the difficulties that layer. In fact, not all Web developers are all very satisfied with JSP technology. Sun technology as there are many different versions, you can choose from a variety of techniques that an alternative technology. This article in-depth view JSP code and introduce some attractive alternatives.
That technical expertise is used to the rough monotone with Web content into a beautiful layer of content. JavaServer Pages (JSP) technology is the Sun of that model, and is part of the J2EE platform, which received great attention. Use JSP technology has advantages and disadvantages. Web developers should be aware of these advantages and disadvantages, and aware of any other place of technology. In fact, there are many options that technology. This article first describes what that technology to solve the problem, then examine the JSP model-specific advantages and disadvantages. Finally, said the technology will introduce some of the other, they can replace the Sun that technology.
Historical Background
Prior to that technology in-depth description, it is necessary to know the technical background of the times. Just 10 years ago, thin client or a new thing. We are still in the era of desktop applications, functionality is limited to 286 microprocessors and now seems dismissive of the 14-inch display. Times have changed! Now my desktop just to run a Web browser, the server from the Sun, IBM, HP, Compaq offers, computing, business logic and content provided by other companies in turn. Then the monitor? Now we use the 21 inch to 25 inch range, plasma widescreen display. So that we can see the complexity of the HTML that they act as a powerful front-end applications. The previous interface has been unable to meet the needs of monotone; we now need to use the gorgeous graphics, moving images can be color coordinated, said, and that it can speed up the rendering speed.
Prerequisite
Now, in the fledgling of the Windows application program after a decade of development, we are still in the great transformation in that mode. Visual Basic and C programmers find that they are still in use back-end system or monotonous Windows application, or in the toolbox to add a language with Web capability, such as Java. If an application can not support at least 3-4 kinds of ML-style languages (eg HTML, XML and WML), if not complete failure, would be considered very bad. Of course, means that we can easily attach great importance to developing the capacity of Web layer.
Proved, using the new Internet and all available languages (Java, C, Perl, Pascal and Ada, etc.) is not as simple as we hope. In the back-end systems using the programming language and use them to generate markup language for the client, the emergence of a large number of problems. With the browser more and more choices (such as DHTML and JavaScript coding), Web urgent need for the field of graphic design knowledge, and can create complex interfaces using standard HTML tools. However, front-end application development capabilities to keep up with the pace of these needs. At this point, that technology came into being.
Specialized tasks that technology: the content (that is, the data did not include that detail) into that that is your cell phone, PalmPilot or a Web browser to see the various user interface. What that technology to solve these problems? Let us find out.
Separation and integration
The main purpose of that technology is to allow separation of content and presentation. In other words, business logic unit (assuming the C or Java and other programming language) does not require specific ways that generate the data. Data or content, in accordance with the original format of the return, not for formatting. Said the technology was subsequently applied to the format or content expressed. The end result is all the data is graphics, formats, colors and logo surrounded.
See Listing 1 and Listing 2 example, look at that original content and application of the technology content differences.
Listing 1: shows the original content, all the data, which could be used in any way.
Russell Crowe
Tom Hanks
Meg Ryan
Mary Stuart Masterson
Alec Baldwin
Ashley Judd
Keanu Reeves
Listing 2: Listing 1 is more complicated than the use of technology to the same data that was decorated, and can be immediately expressed support for HTML in the browser.
HEAD>
Search Results: Actors H2>
BGCOLOR = "# FFFFCC">
Last Name TH>
First Name TH>
TR>
Baldwin TD>
Alec TD>
TR>
Crowe TD>
Russell TD>
TR>
Hanks TD>
Tom TD>
TR>
Judd TD>
Ashley TD>
TR>
Masterson TD>
Mary Stuart TD>
TR>
Reeves TD>
Keanu TD>
TR>
Ryan TD>
Meg TD>
TR>
TABLE>
CENTER>
BODY>
HTML>
Can see the contents of Listing 1 is more clear and easier to use and non-professionals to understand and list the contents of 2, that is specific to the browser. Difficult to extract data or data for other purposes.
This basic distinction, namely, separation of presentation and content, rather than integrate them (at least the user need to use the information), is the premise of any that technology, including JSP technology. In addition, any goal can not be said to achieve this basic technology has not really reflect the original purpose of creation.
Work and duplication of work
In addition to that, and content separation, another measure of the availability of technical indicators that is: how much can eliminate duplication of work. Representation and separation of content between content developers to promote the role of separation. Programmers can focus on the example shows the original content, graphic designer or network administrator is concerned about that. However, graphic designers that receive (or tags) and apply it to content provided by the programmer when the code, there is still some duplication between the roles.
In the simplest case, the designers mark, while developers provide the code and the tag inserted into the said technology. Applications are "start", the content magically become the user interface. Of course, we all know, development is far from over. The next version should be revised, modified interfaces must also add new business rules. It can really test the flexibility of that technology. Although it is easy to update into the layer of original content, but very few graphic designers to easily edit their initial work. Often want to modify that layer (we often according to the sales department of "instigation" modification). Therefore, the question arises: what designers want to modify the content to adjust their work? Is that they provide to the developers of the original markup language page? Maybe not, because the page is likely to insert a custom tag or code (JSP page template engine), is converted to a Java servlet, or modify the content for the completely unrecognized.
Designers often need to redesign the page and re-submit it to the developers. Then the developer will be re-converted to a specific page format to use for that technology. Alternatively, the designer must learn a scripting language, or at least know that the page developer to provide some source code which is against the law. Of course, this method of error-prone and unsafe to use. When you learn that technique allows a clear separation of content and said, you should ensure that the modified layer to minimize duplication of work required.
JSP technology promises
Now, let us look at the specific JSP code. JSP technology designers and developers committed to providing only that they need technology. JSP technology is part of the J2EE platform, which fully shows the Sun Java products for their strong support. To make you understand the popularity of this solution, please try to search in amazon.com about 'JSP'; you will find large number of JSP technology-related books, it will be far more than any single one kind of Java API. In detail JSP technology lead to specific questions, you should clearly understand the promise of this technology.
Content and that
First of all, JSP technology and content and that the separation is the Sun published the most important goal of the JSP page. In fact, some developers complain that the code will out.println (" " + pageInfo.getTitle () + " TITLE> HEAD>"); type to servlet This directly led to the design of JSP. Hard-coded content mixed in the run-time variable is added to the burden of servlet developers, and make developers more difficult to make changes on that layer, even very small changes as well.
JSP technology to solve this problem, it allows the runtime to normal HTML pages (and later, including WHM or other markup language) compiled into Java servlet in fact follow the out.println () example, without the need for developers to write code. It allows you to run when inserted into the variable interpretation of the page.
In a JSP page, HTML fragment shown in Listing 2 should be similar to the example in Listing 3.
<% @ Page import = "com.ibm.display.PageUtils"%>
<% @ Page import = "com.ibm.display.PageInfo"%>
<%
PageInfo pageInfo = (PageInfo) session.getAttribute ("PAGE_DATA")
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
BODY>
HTML>
According to the principles of the original judge, JSP technology (at least in its description of the design) to meet the basic principles of that technology, the same profile as above: the content and that separation.
Code and markup
JSP technical characteristics of the second list may be some problems. JSP code will allow you to tag Java code directly into the page. In the development of JSP specification, Microsoft Active Server Pages (ASP) a big success, so competition between Sun and Microsoft became intense. This led to the emergence of this decision. The name of the JavaServer Pages and Active Server Pages like no accident. And on the number of API features of imitation is intentional. Therefore, those who need to be able to create JSP Java code to their tag.
To demonstrate the Java code to tag in Listing 4 in the JSP code snippet to dynamically add rows as needed to represent actors in Vector in each.
<% @ 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 ()
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
Search Results: Actors H2>
bgcolor = "# FFFFCC">
<%
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
Note that, so far, I just introduced the original design goals JSP technology; JSP technology in the next section describes the problems, I will make their own conclusion to this goal. However, you may have started a bit curious, because the code embedded in JSP pages and JSP technology seems the primary goal (separate content and presentation) conflict. In fact, I have not started this discussion.
Designers and developers
JSP technology, the ultimate (and laudable) goal is to try it in the application development process to form a clear definition of roles. Separation of content through the surface and that, JSP technology can more clearly distinguish the role of designers and developers. Designers use standard HTML, WML, or other suitable language to create tags, and the developer to write code. Of course, many designers are now learning the JavaScript language, so that these designers started learning JSP code is not a surprising thing. Typically, the designer does not simply create a plain tag, they will write a complete JSP page and to the developers. Then after frequent changes, the developer then JSP page as a complete front-end application use. However, the key issue here is still a lot of designers do not learn JSP code, they must be able to work in this environment.
Problems
I have just introduced a technology that should provide good features, and JSP technology attempts to solve specific problems. Now I will turn to the question: JSP technology was built on the basis of a good idea, but some problems. JSP in the choice before the preparation of your application (you may continue to do so), should at least pay attention to a number of easy problems.
You also need to pay attention to often overlooked J2EE programming platform: platform with the API just because does not mean that we must use it. And this idea is equally ridiculous is that many developers use JSP, EJB, or when the JMS API, all trying to use the API if you do not, then their application is not a real "J2EE application" of the. In fact, the platform provides the API is far more than most applications need. If you can not use or JSP technology also skeptical, you can not use it! JSP in the choice of writing applications, carefully study its advantages and disadvantages. Let us look at some of the shortcomings.
Portability and language lock
JSP technology will you lock into a particular language. This should not be given too much attention. At least in my opinion, Java technology is the only choice for enterprise applications. In this area, simply does not exist independently of language solutions. Of course, at this time, I did not Microsoft. NET platform involved in.. Only time can tell us whether this platform can be truly independent of the language (which I doubt it).
However, select JSP technology will force you to use the Java language, at least for content and that is the case. While CORBA can be used for business logic, JSP and servlet code requirements must be familiar with the core Java language. Because many developers J2EE platform through contact with JSP code, it is usually considered a problem.
Mixed and independent
In this article, I always focus on the concept of separation of content and presentation. You may have already impatient, now let us see what JSP can not achieve this goal. As we discussed before, like, JSP claim has been committed to separation of content and presentation, then we can so that it achieved its objectives, is it? Not necessarily the case.
Content and that blur the boundaries between
JSP allows Java code into the markup language page, this is very dangerous feature allows content to that in the mix. Worse, the business logic into the JSP page usually, such as shown in Listing 5.
<% @ 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.Iterator"%>
<% @ Page import = "java.util.Vector"%>
<%
PageInfo pageInfo = (PageInfo) session.getAttribute ("PAGE_DATA")
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
Search Results: Actors H2>
BGCOLOR = "# FFFFCC">
<%
/ / Based on user's permissions, perform search differently (business logic!)
Vector actors = pageInfo.getActors ()
if (pageInfo.getUserInfo (). hasPermission ("ADMINISTRATOR")) (
actors = AdminUtils.getActors (pageInfo.getSearchCriteria ());
) Else (
actors = pageInfo.getActors ();
)
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
JSP's supporters will quickly tell you JSP tag library can help you avoid this problem. Tag Library allows custom tags (such as ) to the JSP page, and then the tag database at run time to resolve the code fragment.
Use custom tags and associated tag library allows to convert the example above the contents shown in Listing 6.
BGCOLOR = "# FFFFCC">
TABLE>
CENTER>
At runtime, the code will execute, and the correct marker to insert the results page. But this does not solve the problem. JSP technology is not grounds for objection is whether the separation of content and presentation, but rather whether it should be separated. As long as the JSP code to allow inline code, so you can easily end inline code changes (especially when deadlines approach) instead of the code is converted to a tag library. If this is not true, then why would immediately Java language than C and C + + is more popular: Java disabled in C, a large number of properties in question, for example, adding a pointer. While you can always stressed you do not need to perform pointer in C sum, or good programmers to insert code scriptlet, we all know what actually will happen. Java language is a better choice because it is prohibited to use these bad habits. But the JSP in this respect more similar to C, allows to achieve some very bad practice.
Test the success of JSP technology to achieve its stated objectives of the other way is to see whether it can achieve this goal in practice; Obviously, if that JSP can not actually achieve its objectives, it is not fair. Most template engines, such as FreeMarker and WebMacro, offer the same inline code function, usually with a language similar to Perl. However, such as Enhydra's XMLC this technology does not allow this type of coding. On the contrary, these technologies will be a pure markup language page as input, then generate Java method. This actually changes the programming process; JSP technology as the application does not use the page as calls from the application logic, but the impact of the page to use the value (Enhydra). With Enhydra, for example, use the XMLC the page is converted to a DOM tree, and then use the HTML DOM binding update page "field" (the Enhydra XMLC more information, please see Resources).
The focus here, JSP technology's ability to achieve goals far beyond XMLC, for example, only the tag library that allows a lot stronger than the XMLC. But the Sun tend to always maintain the overall standard backward compatibility, or at least for a long period of time to maintain backward compatibility. The current version of the JSP 1.1 specification, which allows the use of scriptlets, so in the JSP page within the next few years will support this feature. JSP code in-depth inquiry, please note that the complete separation of its emphasis on the content and the actual realization of that vision and a big gap between, it is at best only pretend to separate the user interface and drive the application code.
Single and Multi-tasking
As mentioned above, the ideal state, the designer should be able to perform alone, only concerned with graphic design, and developers should be able to focus on programming. Therefore, the page designer can be converted to a format suitable for the application, then be processed. For the JSP page for the page is converted to a format suitable for applications that point to the page into JavaBeans, insert inline code and add a custom tag library. The problem is that some designers are using a HTML editor, such as HoTMetaL, Macromedia Dreamweaver or FrontPage, the Editor does not recognize the code scriptlets or tag library, which means that designers actually received only part of a page. Imagine tag library or code snippet only generated a number of table rows, or other format details page, which is how the trouble. Designers use HTML editors are not compatible, you can not see the appearance of these elements. Encoded in the developer, the designer can not easily be modified on the page, then, not only did not clearly defined role, JSP code actually combined these two roles: the developer must perform multiple tasks, must play developers, designers and other roles.
If you still doubt, then please download the J2EE Reference Implementation will be one of the included JSP page is loaded into a WYSIWYG HTML editor, such as Dreamweaver. Page immediately fill some of the yellow area, to tell you the page that contains all the " wrong "mark. Of course, the yellow content from the JSP tags and code, not the page what the real error occurred.
So far, not been there to support JSP WYSIWYG editor functionality, I have not heard of any related projects. Although the template engine with the same problem, but many Java-based solutions, such as my favorite Enhydra, allow you to mark pages as input provided to the said technology. In this case, the designer can require frequent changes and re-mark the page provided. Said the technology to run the engine or the compiler will mark the page into the appropriate format, and does not require any code changes (typically). Finally got the desired results: designers and developers carry out their duties.
So, pay attention to the commitments made by JSP technology and its actual delivery of the implementation. In practice, in a JSP technology-driven environment to be effective, must allow developers to handle most of the mark, or at least allow designers to learn some JSP code.
HTML and XML
JSP technology one of the most serious flaws (and often overlooked a flaw) is that it is not compatible with XML. More specifically, and in particular areas for HTML, JSP page does not require compatibility with XHTML. XHTML is a World Wide Web Consortium (W3C) specification, currently being replaced by HTML 4.0.XHTML in achieving the well-formed XML document defines the HTML tag set terms. For example,
Tag must be converted to
To ensure XML compatibility (if this example does not explain clearly, you can access reference materials listed in the XML specification, and the developerWorks article on XHTML). The same rule applies to the image tags, and XHTML 1.1 (forthcoming), most of the font properties and other styles to be moved to the CSS style sheet. In addition, most standard HTML documents can be easily converted to XHTML 1.0, which means you can use any XML-compliant parser to read, such as Apache Xerces, and can be processed as XML.
You may ask "What relationship?." The answer is at stake. Because XML is fast becoming a between applications and applications to communicate within a global standard. XML format using the pass book, you can make any use of the basic XML data binding application functionality to easily use your application data. Imagine your data by migrating to XML format, you can conduct online transactions with credit card company! Most cases, your data that need to interact with other companies. The most common situation is that the portal application, it accepts content from various providers (for example, weather information, stock quotes and news), is usually marked with a provider. However, the code JSP pages and custom tag libraries with mixed and can not in this environment, good work.
JSP page has a few well-formed XML document, and do not attach importance to compliance with XHTML, and XHTML markup language that does not permit use of JSP custom tag libraries. But more importantly, inserted into the JSP page code snippet does not belong to any marked form, so when another application to deal with them, will produce the parser to load error.
To challenge you, let us first look at the situation. If the application allows the client JSP page from the initial treatment, the results will generate pure HTML (or WML, VoXML, etc.). However, most requests for data applications that use a certain amount of cache, because the network is very expensive and from overhead. In these cases, the cache of pages will return outdated data. Therefore, you may prefer to return XML compliant with the results, it is best to use a static form. The JSP technology in these situations do nothing; JSP page must always be processed at run time to remove the JSP code scriptlets and tag libraries.
Look at the most critical test: that technology can do some other point? The answer is yes. This area is the most authoritative leader Apache Cocoon project, it is entirely built on XML and an XSLT style sheet application (available at run time or static state application) basis. As the XML Server Pages (in the Cocoon framework called XSP) is actually XML documents, thus always compatible with XML. Tea and Enhydra XMLC so as to allow importation of pure markup language page of the technology can do, although their purpose is not here. In these cases, the user can use XHTML or standard HTML. In addition, it is better than the JSP technology, can not be static because the JSP to achieve well-formed XML.
Conclusion
I hope my efforts can allow you to further understand the advantages and disadvantages of JSP technology, and you can be a number of JSP technology as a substitute for other presentation technology. Now, you may be the J2EE programming model also had some doubts. If you wish to further research platform choice, you can in the Apache Cocoon, Enhydra, and various template engine to find an alternative to JSP technology.
Finally, remember, this is not recommended that you use JSP or avoid it, even though the surface like this. My aim is to encourage you to conduct a detailed analysis of any technology to ensure that it is the right choice. As the same programming model, and sometimes they are right, but sometimes they do not fit. Some more more, finds the most suitable technologies and to make informed decisions, rather than a hasty decision.
More topics
Featured Posts
Sheng Hong automotive management system
Transformation of the Chinese system integrators Which Way?
Production management system
Survival of the internationalization of software companies
Nine risk of intrusion detection systems and countermeasures
Tsinghua Tong Fang RFID security system stadium tickets
RF125 garment factory management system: a new generation of Revelation Clothing Industry
Enterprise instant messaging GKE
Integration of four systems: four stages of the decision on the future trend of ERP
You legislative branches of the central forms of social security identification entry system
BGCOLOR = "# FFFFCC">
TR>
TR>
TR>
TR>
TR>
TR>
TR>
TR>
TABLE>
CENTER>
BODY>
HTML>
Can see the contents of Listing 1 is more clear and easier to use and non-professionals to understand and list the contents of 2, that is specific to the browser. Difficult to extract data or data for other purposes.
This basic distinction, namely, separation of presentation and content, rather than integrate them (at least the user need to use the information), is the premise of any that technology, including JSP technology. In addition, any goal can not be said to achieve this basic technology has not really reflect the original purpose of creation.
Work and duplication of work
In addition to that, and content separation, another measure of the availability of technical indicators that is: how much can eliminate duplication of work. Representation and separation of content between content developers to promote the role of separation. Programmers can focus on the example shows the original content, graphic designer or network administrator is concerned about that. However, graphic designers that receive (or tags) and apply it to content provided by the programmer when the code, there is still some duplication between the roles.
In the simplest case, the designers mark, while developers provide the code and the tag inserted into the said technology. Applications are "start", the content magically become the user interface. Of course, we all know, development is far from over. The next version should be revised, modified interfaces must also add new business rules. It can really test the flexibility of that technology. Although it is easy to update into the layer of original content, but very few graphic designers to easily edit their initial work. Often want to modify that layer (we often according to the sales department of "instigation" modification). Therefore, the question arises: what designers want to modify the content to adjust their work? Is that they provide to the developers of the original markup language page? Maybe not, because the page is likely to insert a custom tag or code (JSP page template engine), is converted to a Java servlet, or modify the content for the completely unrecognized.
Designers often need to redesign the page and re-submit it to the developers. Then the developer will be re-converted to a specific page format to use for that technology. Alternatively, the designer must learn a scripting language, or at least know that the page developer to provide some source code which is against the law. Of course, this method of error-prone and unsafe to use. When you learn that technique allows a clear separation of content and said, you should ensure that the modified layer to minimize duplication of work required.
JSP technology promises
Now, let us look at the specific JSP code. JSP technology designers and developers committed to providing only that they need technology. JSP technology is part of the J2EE platform, which fully shows the Sun Java products for their strong support. To make you understand the popularity of this solution, please try to search in amazon.com about 'JSP'; you will find large number of JSP technology-related books, it will be far more than any single one kind of Java API. In detail JSP technology lead to specific questions, you should clearly understand the promise of this technology.
Content and that
First of all, JSP technology and content and that the separation is the Sun published the most important goal of the JSP page. In fact, some developers complain that the code will out.println ("
JSP technology to solve this problem, it allows the runtime to normal HTML pages (and later, including WHM or other markup language) compiled into Java servlet in fact follow the out.println () example, without the need for developers to write code. It allows you to run when inserted into the variable interpretation of the page.
In a JSP page, HTML fragment shown in Listing 2 should be similar to the example in Listing 3.
<% @ Page import = "com.ibm.display.PageUtils"%>
<% @ Page import = "com.ibm.display.PageInfo"%>
<%
PageInfo pageInfo = (PageInfo) session.getAttribute ("PAGE_DATA")
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
BODY>
HTML>
According to the principles of the original judge, JSP technology (at least in its description of the design) to meet the basic principles of that technology, the same profile as above: the content and that separation.
Code and markup
JSP technical characteristics of the second list may be some problems. JSP code will allow you to tag Java code directly into the page. In the development of JSP specification, Microsoft Active Server Pages (ASP) a big success, so competition between Sun and Microsoft became intense. This led to the emergence of this decision. The name of the JavaServer Pages and Active Server Pages like no accident. And on the number of API features of imitation is intentional. Therefore, those who need to be able to create JSP Java code to their tag.
To demonstrate the Java code to tag in Listing 4 in the JSP code snippet to dynamically add rows as needed to represent actors in Vector in each.
<% @ 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 ()
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
Search Results: Actors H2>
bgcolor = "# FFFFCC">
<%
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
Note that, so far, I just introduced the original design goals JSP technology; JSP technology in the next section describes the problems, I will make their own conclusion to this goal. However, you may have started a bit curious, because the code embedded in JSP pages and JSP technology seems the primary goal (separate content and presentation) conflict. In fact, I have not started this discussion.
Designers and developers
JSP technology, the ultimate (and laudable) goal is to try it in the application development process to form a clear definition of roles. Separation of content through the surface and that, JSP technology can more clearly distinguish the role of designers and developers. Designers use standard HTML, WML, or other suitable language to create tags, and the developer to write code. Of course, many designers are now learning the JavaScript language, so that these designers started learning JSP code is not a surprising thing. Typically, the designer does not simply create a plain tag, they will write a complete JSP page and to the developers. Then after frequent changes, the developer then JSP page as a complete front-end application use. However, the key issue here is still a lot of designers do not learn JSP code, they must be able to work in this environment.
Problems
I have just introduced a technology that should provide good features, and JSP technology attempts to solve specific problems. Now I will turn to the question: JSP technology was built on the basis of a good idea, but some problems. JSP in the choice before the preparation of your application (you may continue to do so), should at least pay attention to a number of easy problems.
You also need to pay attention to often overlooked J2EE programming platform: platform with the API just because does not mean that we must use it. And this idea is equally ridiculous is that many developers use JSP, EJB, or when the JMS API, all trying to use the API if you do not, then their application is not a real "J2EE application" of the. In fact, the platform provides the API is far more than most applications need. If you can not use or JSP technology also skeptical, you can not use it! JSP in the choice of writing applications, carefully study its advantages and disadvantages. Let us look at some of the shortcomings.
Portability and language lock
JSP technology will you lock into a particular language. This should not be given too much attention. At least in my opinion, Java technology is the only choice for enterprise applications. In this area, simply does not exist independently of language solutions. Of course, at this time, I did not Microsoft. NET platform involved in.. Only time can tell us whether this platform can be truly independent of the language (which I doubt it).
However, select JSP technology will force you to use the Java language, at least for content and that is the case. While CORBA can be used for business logic, JSP and servlet code requirements must be familiar with the core Java language. Because many developers J2EE platform through contact with JSP code, it is usually considered a problem.
Mixed and independent
In this article, I always focus on the concept of separation of content and presentation. You may have already impatient, now let us see what JSP can not achieve this goal. As we discussed before, like, JSP claim has been committed to separation of content and presentation, then we can so that it achieved its objectives, is it? Not necessarily the case.
Content and that blur the boundaries between
JSP allows Java code into the markup language page, this is very dangerous feature allows content to that in the mix. Worse, the business logic into the JSP page usually, such as shown in Listing 5.
<% @ 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.Iterator"%>
<% @ Page import = "java.util.Vector"%>
<%
PageInfo pageInfo = (PageInfo) session.getAttribute ("PAGE_DATA")
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
Search Results: Actors H2>
BGCOLOR = "# FFFFCC">
<%
/ / Based on user's permissions, perform search differently (business logic!)
Vector actors = pageInfo.getActors ()
if (pageInfo.getUserInfo (). hasPermission ("ADMINISTRATOR")) (
actors = AdminUtils.getActors (pageInfo.getSearchCriteria ());
) Else (
actors = pageInfo.getActors ();
)
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
JSP's supporters will quickly tell you JSP tag library can help you avoid this problem. Tag Library allows custom tags (such as ) to the JSP page, and then the tag database at run time to resolve the code fragment.
Use custom tags and associated tag library allows to convert the example above the contents shown in Listing 6.
BGCOLOR = "# FFFFCC">
TABLE>
CENTER>
At runtime, the code will execute, and the correct marker to insert the results page. But this does not solve the problem. JSP technology is not grounds for objection is whether the separation of content and presentation, but rather whether it should be separated. As long as the JSP code to allow inline code, so you can easily end inline code changes (especially when deadlines approach) instead of the code is converted to a tag library. If this is not true, then why would immediately Java language than C and C + + is more popular: Java disabled in C, a large number of properties in question, for example, adding a pointer. While you can always stressed you do not need to perform pointer in C sum, or good programmers to insert code scriptlet, we all know what actually will happen. Java language is a better choice because it is prohibited to use these bad habits. But the JSP in this respect more similar to C, allows to achieve some very bad practice.
Test the success of JSP technology to achieve its stated objectives of the other way is to see whether it can achieve this goal in practice; Obviously, if that JSP can not actually achieve its objectives, it is not fair. Most template engines, such as FreeMarker and WebMacro, offer the same inline code function, usually with a language similar to Perl. However, such as Enhydra's XMLC this technology does not allow this type of coding. On the contrary, these technologies will be a pure markup language page as input, then generate Java method. This actually changes the programming process; JSP technology as the application does not use the page as calls from the application logic, but the impact of the page to use the value (Enhydra). With Enhydra, for example, use the XMLC the page is converted to a DOM tree, and then use the HTML DOM binding update page "field" (the Enhydra XMLC more information, please see Resources).
The focus here, JSP technology's ability to achieve goals far beyond XMLC, for example, only the tag library that allows a lot stronger than the XMLC. But the Sun tend to always maintain the overall standard backward compatibility, or at least for a long period of time to maintain backward compatibility. The current version of the JSP 1.1 specification, which allows the use of scriptlets, so in the JSP page within the next few years will support this feature. JSP code in-depth inquiry, please note that the complete separation of its emphasis on the content and the actual realization of that vision and a big gap between, it is at best only pretend to separate the user interface and drive the application code.
Single and Multi-tasking
As mentioned above, the ideal state, the designer should be able to perform alone, only concerned with graphic design, and developers should be able to focus on programming. Therefore, the page designer can be converted to a format suitable for the application, then be processed. For the JSP page for the page is converted to a format suitable for applications that point to the page into JavaBeans, insert inline code and add a custom tag library. The problem is that some designers are using a HTML editor, such as HoTMetaL, Macromedia Dreamweaver or FrontPage, the Editor does not recognize the code scriptlets or tag library, which means that designers actually received only part of a page. Imagine tag library or code snippet only generated a number of table rows, or other format details page, which is how the trouble. Designers use HTML editors are not compatible, you can not see the appearance of these elements. Encoded in the developer, the designer can not easily be modified on the page, then, not only did not clearly defined role, JSP code actually combined these two roles: the developer must perform multiple tasks, must play developers, designers and other roles.
If you still doubt, then please download the J2EE Reference Implementation will be one of the included JSP page is loaded into a WYSIWYG HTML editor, such as Dreamweaver. Page immediately fill some of the yellow area, to tell you the page that contains all the " wrong "mark. Of course, the yellow content from the JSP tags and code, not the page what the real error occurred.
So far, not been there to support JSP WYSIWYG editor functionality, I have not heard of any related projects. Although the template engine with the same problem, but many Java-based solutions, such as my favorite Enhydra, allow you to mark pages as input provided to the said technology. In this case, the designer can require frequent changes and re-mark the page provided. Said the technology to run the engine or the compiler will mark the page into the appropriate format, and does not require any code changes (typically). Finally got the desired results: designers and developers carry out their duties.
So, pay attention to the commitments made by JSP technology and its actual delivery of the implementation. In practice, in a JSP technology-driven environment to be effective, must allow developers to handle most of the mark, or at least allow designers to learn some JSP code.
HTML and XML
JSP technology one of the most serious flaws (and often overlooked a flaw) is that it is not compatible with XML. More specifically, and in particular areas for HTML, JSP page does not require compatibility with XHTML. XHTML is a World Wide Web Consortium (W3C) specification, currently being replaced by HTML 4.0.XHTML in achieving the well-formed XML document defines the HTML tag set terms. For example,
Tag must be converted to
To ensure XML compatibility (if this example does not explain clearly, you can access reference materials listed in the XML specification, and the developerWorks article on XHTML). The same rule applies to the image tags, and XHTML 1.1 (forthcoming), most of the font properties and other styles to be moved to the CSS style sheet. In addition, most standard HTML documents can be easily converted to XHTML 1.0, which means you can use any XML-compliant parser to read, such as Apache Xerces, and can be processed as XML.
You may ask "What relationship?." The answer is at stake. Because XML is fast becoming a between applications and applications to communicate within a global standard. XML format using the pass book, you can make any use of the basic XML data binding application functionality to easily use your application data. Imagine your data by migrating to XML format, you can conduct online transactions with credit card company! Most cases, your data that need to interact with other companies. The most common situation is that the portal application, it accepts content from various providers (for example, weather information, stock quotes and news), is usually marked with a provider. However, the code JSP pages and custom tag libraries with mixed and can not in this environment, good work.
JSP page has a few well-formed XML document, and do not attach importance to compliance with XHTML, and XHTML markup language that does not permit use of JSP custom tag libraries. But more importantly, inserted into the JSP page code snippet does not belong to any marked form, so when another application to deal with them, will produce the parser to load error.
To challenge you, let us first look at the situation. If the application allows the client JSP page from the initial treatment, the results will generate pure HTML (or WML, VoXML, etc.). However, most requests for data applications that use a certain amount of cache, because the network is very expensive and from overhead. In these cases, the cache of pages will return outdated data. Therefore, you may prefer to return XML compliant with the results, it is best to use a static form. The JSP technology in these situations do nothing; JSP page must always be processed at run time to remove the JSP code scriptlets and tag libraries.
Look at the most critical test: that technology can do some other point? The answer is yes. This area is the most authoritative leader Apache Cocoon project, it is entirely built on XML and an XSLT style sheet application (available at run time or static state application) basis. As the XML Server Pages (in the Cocoon framework called XSP) is actually XML documents, thus always compatible with XML. Tea and Enhydra XMLC so as to allow importation of pure markup language page of the technology can do, although their purpose is not here. In these cases, the user can use XHTML or standard HTML. In addition, it is better than the JSP technology, can not be static because the JSP to achieve well-formed XML.
Conclusion
I hope my efforts can allow you to further understand the advantages and disadvantages of JSP technology, and you can be a number of JSP technology as a substitute for other presentation technology. Now, you may be the J2EE programming model also had some doubts. If you wish to further research platform choice, you can in the Apache Cocoon, Enhydra, and various template engine to find an alternative to JSP technology.
Finally, remember, this is not recommended that you use JSP or avoid it, even though the surface like this. My aim is to encourage you to conduct a detailed analysis of any technology to ensure that it is the right choice. As the same programming model, and sometimes they are right, but sometimes they do not fit. Some more more, finds the most suitable technologies and to make informed decisions, rather than a hasty decision.
More topics
Featured Posts
Sheng Hong automotive management system
Transformation of the Chinese system integrators Which Way?
Production management system
Survival of the internationalization of software companies
Nine risk of intrusion detection systems and countermeasures
Tsinghua Tong Fang RFID security system stadium tickets
RF125 garment factory management system: a new generation of Revelation Clothing Industry
Enterprise instant messaging GKE
Integration of four systems: four stages of the decision on the future trend of ERP
You legislative branches of the central forms of social security identification entry system
bgcolor = "# FFFFCC">
<%
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
Note that, so far, I just introduced the original design goals JSP technology; JSP technology in the next section describes the problems, I will make their own conclusion to this goal. However, you may have started a bit curious, because the code embedded in JSP pages and JSP technology seems the primary goal (separate content and presentation) conflict. In fact, I have not started this discussion.
Designers and developers
JSP technology, the ultimate (and laudable) goal is to try it in the application development process to form a clear definition of roles. Separation of content through the surface and that, JSP technology can more clearly distinguish the role of designers and developers. Designers use standard HTML, WML, or other suitable language to create tags, and the developer to write code. Of course, many designers are now learning the JavaScript language, so that these designers started learning JSP code is not a surprising thing. Typically, the designer does not simply create a plain tag, they will write a complete JSP page and to the developers. Then after frequent changes, the developer then JSP page as a complete front-end application use. However, the key issue here is still a lot of designers do not learn JSP code, they must be able to work in this environment.
Problems
I have just introduced a technology that should provide good features, and JSP technology attempts to solve specific problems. Now I will turn to the question: JSP technology was built on the basis of a good idea, but some problems. JSP in the choice before the preparation of your application (you may continue to do so), should at least pay attention to a number of easy problems.
You also need to pay attention to often overlooked J2EE programming platform: platform with the API just because does not mean that we must use it. And this idea is equally ridiculous is that many developers use JSP, EJB, or when the JMS API, all trying to use the API if you do not, then their application is not a real "J2EE application" of the. In fact, the platform provides the API is far more than most applications need. If you can not use or JSP technology also skeptical, you can not use it! JSP in the choice of writing applications, carefully study its advantages and disadvantages. Let us look at some of the shortcomings.
Portability and language lock
JSP technology will you lock into a particular language. This should not be given too much attention. At least in my opinion, Java technology is the only choice for enterprise applications. In this area, simply does not exist independently of language solutions. Of course, at this time, I did not Microsoft. NET platform involved in.. Only time can tell us whether this platform can be truly independent of the language (which I doubt it).
However, select JSP technology will force you to use the Java language, at least for content and that is the case. While CORBA can be used for business logic, JSP and servlet code requirements must be familiar with the core Java language. Because many developers J2EE platform through contact with JSP code, it is usually considered a problem.
Mixed and independent
In this article, I always focus on the concept of separation of content and presentation. You may have already impatient, now let us see what JSP can not achieve this goal. As we discussed before, like, JSP claim has been committed to separation of content and presentation, then we can so that it achieved its objectives, is it? Not necessarily the case.
Content and that blur the boundaries between
JSP allows Java code into the markup language page, this is very dangerous feature allows content to that in the mix. Worse, the business logic into the JSP page usually, such as shown in Listing 5.
<% @ 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.Iterator"%>
<% @ Page import = "java.util.Vector"%>
<%
PageInfo pageInfo = (PageInfo) session.getAttribute ("PAGE_DATA")
%>
<% = PageInfo.getTitle ()%>
TITLE>
HEAD>
Search Results: Actors H2>
BGCOLOR = "# FFFFCC">
<%
/ / Based on user's permissions, perform search differently (business logic!)
Vector actors = pageInfo.getActors ()
if (pageInfo.getUserInfo (). hasPermission ("ADMINISTRATOR")) (
actors = AdminUtils.getActors (pageInfo.getSearchCriteria ());
) Else (
actors = pageInfo.getActors ();
)
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
JSP's supporters will quickly tell you JSP tag library can help you avoid this problem. Tag Library allows custom tags (such as ) to the JSP page, and then the tag database at run time to resolve the code fragment.
Use custom tags and associated tag library allows to convert the example above the contents shown in Listing 6.
BGCOLOR = "# FFFFCC">
TABLE>
CENTER>
At runtime, the code will execute, and the correct marker to insert the results page. But this does not solve the problem. JSP technology is not grounds for objection is whether the separation of content and presentation, but rather whether it should be separated. As long as the JSP code to allow inline code, so you can easily end inline code changes (especially when deadlines approach) instead of the code is converted to a tag library. If this is not true, then why would immediately Java language than C and C + + is more popular: Java disabled in C, a large number of properties in question, for example, adding a pointer. While you can always stressed you do not need to perform pointer in C sum, or good programmers to insert code scriptlet, we all know what actually will happen. Java language is a better choice because it is prohibited to use these bad habits. But the JSP in this respect more similar to C, allows to achieve some very bad practice.
Test the success of JSP technology to achieve its stated objectives of the other way is to see whether it can achieve this goal in practice; Obviously, if that JSP can not actually achieve its objectives, it is not fair. Most template engines, such as FreeMarker and WebMacro, offer the same inline code function, usually with a language similar to Perl. However, such as Enhydra's XMLC this technology does not allow this type of coding. On the contrary, these technologies will be a pure markup language page as input, then generate Java method. This actually changes the programming process; JSP technology as the application does not use the page as calls from the application logic, but the impact of the page to use the value (Enhydra). With Enhydra, for example, use the XMLC the page is converted to a DOM tree, and then use the HTML DOM binding update page "field" (the Enhydra XMLC more information, please see Resources).
The focus here, JSP technology's ability to achieve goals far beyond XMLC, for example, only the tag library that allows a lot stronger than the XMLC. But the Sun tend to always maintain the overall standard backward compatibility, or at least for a long period of time to maintain backward compatibility. The current version of the JSP 1.1 specification, which allows the use of scriptlets, so in the JSP page within the next few years will support this feature. JSP code in-depth inquiry, please note that the complete separation of its emphasis on the content and the actual realization of that vision and a big gap between, it is at best only pretend to separate the user interface and drive the application code.
Single and Multi-tasking
As mentioned above, the ideal state, the designer should be able to perform alone, only concerned with graphic design, and developers should be able to focus on programming. Therefore, the page designer can be converted to a format suitable for the application, then be processed. For the JSP page for the page is converted to a format suitable for applications that point to the page into JavaBeans, insert inline code and add a custom tag library. The problem is that some designers are using a HTML editor, such as HoTMetaL, Macromedia Dreamweaver or FrontPage, the Editor does not recognize the code scriptlets or tag library, which means that designers actually received only part of a page. Imagine tag library or code snippet only generated a number of table rows, or other format details page, which is how the trouble. Designers use HTML editors are not compatible, you can not see the appearance of these elements. Encoded in the developer, the designer can not easily be modified on the page, then, not only did not clearly defined role, JSP code actually combined these two roles: the developer must perform multiple tasks, must play developers, designers and other roles.
If you still doubt, then please download the J2EE Reference Implementation will be one of the included JSP page is loaded into a WYSIWYG HTML editor, such as Dreamweaver. Page immediately fill some of the yellow area, to tell you the page that contains all the " wrong "mark. Of course, the yellow content from the JSP tags and code, not the page what the real error occurred.
So far, not been there to support JSP WYSIWYG editor functionality, I have not heard of any related projects. Although the template engine with the same problem, but many Java-based solutions, such as my favorite Enhydra, allow you to mark pages as input provided to the said technology. In this case, the designer can require frequent changes and re-mark the page provided. Said the technology to run the engine or the compiler will mark the page into the appropriate format, and does not require any code changes (typically). Finally got the desired results: designers and developers carry out their duties.
So, pay attention to the commitments made by JSP technology and its actual delivery of the implementation. In practice, in a JSP technology-driven environment to be effective, must allow developers to handle most of the mark, or at least allow designers to learn some JSP code.
HTML and XML
JSP technology one of the most serious flaws (and often overlooked a flaw) is that it is not compatible with XML. More specifically, and in particular areas for HTML, JSP page does not require compatibility with XHTML. XHTML is a World Wide Web Consortium (W3C) specification, currently being replaced by HTML 4.0.XHTML in achieving the well-formed XML document defines the HTML tag set terms. For example,
Tag must be converted to
To ensure XML compatibility (if this example does not explain clearly, you can access reference materials listed in the XML specification, and the developerWorks article on XHTML). The same rule applies to the image tags, and XHTML 1.1 (forthcoming), most of the font properties and other styles to be moved to the CSS style sheet. In addition, most standard HTML documents can be easily converted to XHTML 1.0, which means you can use any XML-compliant parser to read, such as Apache Xerces, and can be processed as XML.
You may ask "What relationship?." The answer is at stake. Because XML is fast becoming a between applications and applications to communicate within a global standard. XML format using the pass book, you can make any use of the basic XML data binding application functionality to easily use your application data. Imagine your data by migrating to XML format, you can conduct online transactions with credit card company! Most cases, your data that need to interact with other companies. The most common situation is that the portal application, it accepts content from various providers (for example, weather information, stock quotes and news), is usually marked with a provider. However, the code JSP pages and custom tag libraries with mixed and can not in this environment, good work.
JSP page has a few well-formed XML document, and do not attach importance to compliance with XHTML, and XHTML markup language that does not permit use of JSP custom tag libraries. But more importantly, inserted into the JSP page code snippet does not belong to any marked form, so when another application to deal with them, will produce the parser to load error.
To challenge you, let us first look at the situation. If the application allows the client JSP page from the initial treatment, the results will generate pure HTML (or WML, VoXML, etc.). However, most requests for data applications that use a certain amount of cache, because the network is very expensive and from overhead. In these cases, the cache of pages will return outdated data. Therefore, you may prefer to return XML compliant with the results, it is best to use a static form. The JSP technology in these situations do nothing; JSP page must always be processed at run time to remove the JSP code scriptlets and tag libraries.
Look at the most critical test: that technology can do some other point? The answer is yes. This area is the most authoritative leader Apache Cocoon project, it is entirely built on XML and an XSLT style sheet application (available at run time or static state application) basis. As the XML Server Pages (in the Cocoon framework called XSP) is actually XML documents, thus always compatible with XML. Tea and Enhydra XMLC so as to allow importation of pure markup language page of the technology can do, although their purpose is not here. In these cases, the user can use XHTML or standard HTML. In addition, it is better than the JSP technology, can not be static because the JSP to achieve well-formed XML.
Conclusion
I hope my efforts can allow you to further understand the advantages and disadvantages of JSP technology, and you can be a number of JSP technology as a substitute for other presentation technology. Now, you may be the J2EE programming model also had some doubts. If you wish to further research platform choice, you can in the Apache Cocoon, Enhydra, and various template engine to find an alternative to JSP technology.
Finally, remember, this is not recommended that you use JSP or avoid it, even though the surface like this. My aim is to encourage you to conduct a detailed analysis of any technology to ensure that it is the right choice. As the same programming model, and sometimes they are right, but sometimes they do not fit. Some more more, finds the most suitable technologies and to make informed decisions, rather than a hasty decision.
More topics
Featured Posts
Sheng Hong automotive management system
Transformation of the Chinese system integrators Which Way?
Production management system
Survival of the internationalization of software companies
Nine risk of intrusion detection systems and countermeasures
Tsinghua Tong Fang RFID security system stadium tickets
RF125 garment factory management system: a new generation of Revelation Clothing Industry
Enterprise instant messaging GKE
Integration of four systems: four stages of the decision on the future trend of ERP
You legislative branches of the central forms of social security identification entry system
BGCOLOR = "# FFFFCC">
<%
/ / Based on user's permissions, perform search differently (business logic!)
Vector actors = pageInfo.getActors ()
if (pageInfo.getUserInfo (). hasPermission ("ADMINISTRATOR")) (
actors = AdminUtils.getActors (pageInfo.getSearchCriteria ());
) Else (
actors = pageInfo.getActors ();
)
for (Iterator i = actors.iterator (); i.hasNext ()) (
Actor actor = (Actor) i.next ();
%>
<% = Actor.getLastName ()%>
TH>
<% = Actor.getFirstName ()%>
TH>
TR>
<%
)
%>
TABLE>
CENTER>
BODY>
HTML>
JSP's supporters will quickly tell you JSP tag library can help you avoid this problem. Tag Library allows custom tags (such as
Use custom tags and associated tag library allows to convert the example above the contents shown in Listing 6.
BGCOLOR = "# FFFFCC">
TABLE>
CENTER>
At runtime, the code will execute, and the correct marker to insert the results page. But this does not solve the problem. JSP technology is not grounds for objection is whether the separation of content and presentation, but rather whether it should be separated. As long as the JSP code to allow inline code, so you can easily end inline code changes (especially when deadlines approach) instead of the code is converted to a tag library. If this is not true, then why would immediately Java language than C and C + + is more popular: Java disabled in C, a large number of properties in question, for example, adding a pointer. While you can always stressed you do not need to perform pointer in C sum, or good programmers to insert code scriptlet, we all know what actually will happen. Java language is a better choice because it is prohibited to use these bad habits. But the JSP in this respect more similar to C, allows to achieve some very bad practice.
Test the success of JSP technology to achieve its stated objectives of the other way is to see whether it can achieve this goal in practice; Obviously, if that JSP can not actually achieve its objectives, it is not fair. Most template engines, such as FreeMarker and WebMacro, offer the same inline code function, usually with a language similar to Perl. However, such as Enhydra's XMLC this technology does not allow this type of coding. On the contrary, these technologies will be a pure markup language page as input, then generate Java method. This actually changes the programming process; JSP technology as the application does not use the page as calls from the application logic, but the impact of the page to use the value (Enhydra). With Enhydra, for example, use the XMLC the page is converted to a DOM tree, and then use the HTML DOM binding update page "field" (the Enhydra XMLC more information, please see Resources).
The focus here, JSP technology's ability to achieve goals far beyond XMLC, for example, only the tag library that allows a lot stronger than the XMLC. But the Sun tend to always maintain the overall standard backward compatibility, or at least for a long period of time to maintain backward compatibility. The current version of the JSP 1.1 specification, which allows the use of scriptlets, so in the JSP page within the next few years will support this feature. JSP code in-depth inquiry, please note that the complete separation of its emphasis on the content and the actual realization of that vision and a big gap between, it is at best only pretend to separate the user interface and drive the application code.
Single and Multi-tasking
As mentioned above, the ideal state, the designer should be able to perform alone, only concerned with graphic design, and developers should be able to focus on programming. Therefore, the page designer can be converted to a format suitable for the application, then be processed. For the JSP page for the page is converted to a format suitable for applications that point to the page into JavaBeans, insert inline code and add a custom tag library. The problem is that some designers are using a HTML editor, such as HoTMetaL, Macromedia Dreamweaver or FrontPage, the Editor does not recognize the code scriptlets or tag library, which means that designers actually received only part of a page. Imagine tag library or code snippet only generated a number of table rows, or other format details page, which is how the trouble. Designers use HTML editors are not compatible, you can not see the appearance of these elements. Encoded in the developer, the designer can not easily be modified on the page, then, not only did not clearly defined role, JSP code actually combined these two roles: the developer must perform multiple tasks, must play developers, designers and other roles.
If you still doubt, then please download the J2EE Reference Implementation will be one of the included JSP page is loaded into a WYSIWYG HTML editor, such as Dreamweaver. Page immediately fill some of the yellow area, to tell you the page that contains all the " wrong "mark. Of course, the yellow content from the JSP tags and code, not the page what the real error occurred.
So far, not been there to support JSP WYSIWYG editor functionality, I have not heard of any related projects. Although the template engine with the same problem, but many Java-based solutions, such as my favorite Enhydra, allow you to mark pages as input provided to the said technology. In this case, the designer can require frequent changes and re-mark the page provided. Said the technology to run the engine or the compiler will mark the page into the appropriate format, and does not require any code changes (typically). Finally got the desired results: designers and developers carry out their duties.
So, pay attention to the commitments made by JSP technology and its actual delivery of the implementation. In practice, in a JSP technology-driven environment to be effective, must allow developers to handle most of the mark, or at least allow designers to learn some JSP code.
HTML and XML
JSP technology one of the most serious flaws (and often overlooked a flaw) is that it is not compatible with XML. More specifically, and in particular areas for HTML, JSP page does not require compatibility with XHTML. XHTML is a World Wide Web Consortium (W3C) specification, currently being replaced by HTML 4.0.XHTML in achieving the well-formed XML document defines the HTML tag set terms. For example,
Tag must be converted to
To ensure XML compatibility (if this example does not explain clearly, you can access reference materials listed in the XML specification, and the developerWorks article on XHTML). The same rule applies to the image tags, and XHTML 1.1 (forthcoming), most of the font properties and other styles to be moved to the CSS style sheet. In addition, most standard HTML documents can be easily converted to XHTML 1.0, which means you can use any XML-compliant parser to read, such as Apache Xerces, and can be processed as XML.
You may ask "What relationship?." The answer is at stake. Because XML is fast becoming a between applications and applications to communicate within a global standard. XML format using the pass book, you can make any use of the basic XML data binding application functionality to easily use your application data. Imagine your data by migrating to XML format, you can conduct online transactions with credit card company! Most cases, your data that need to interact with other companies. The most common situation is that the portal application, it accepts content from various providers (for example, weather information, stock quotes and news), is usually marked with a provider. However, the code JSP pages and custom tag libraries with mixed and can not in this environment, good work.
JSP page has a few well-formed XML document, and do not attach importance to compliance with XHTML, and XHTML markup language that does not permit use of JSP custom tag libraries. But more importantly, inserted into the JSP page code snippet does not belong to any marked form, so when another application to deal with them, will produce the parser to load error.
To challenge you, let us first look at the situation. If the application allows the client JSP page from the initial treatment, the results will generate pure HTML (or WML, VoXML, etc.). However, most requests for data applications that use a certain amount of cache, because the network is very expensive and from overhead. In these cases, the cache of pages will return outdated data. Therefore, you may prefer to return XML compliant with the results, it is best to use a static form. The JSP technology in these situations do nothing; JSP page must always be processed at run time to remove the JSP code scriptlets and tag libraries.
Look at the most critical test: that technology can do some other point? The answer is yes. This area is the most authoritative leader Apache Cocoon project, it is entirely built on XML and an XSLT style sheet application (available at run time or static state application) basis. As the XML Server Pages (in the Cocoon framework called XSP) is actually XML documents, thus always compatible with XML. Tea and Enhydra XMLC so as to allow importation of pure markup language page of the technology can do, although their purpose is not here. In these cases, the user can use XHTML or standard HTML. In addition, it is better than the JSP technology, can not be static because the JSP to achieve well-formed XML.
Conclusion
I hope my efforts can allow you to further understand the advantages and disadvantages of JSP technology, and you can be a number of JSP technology as a substitute for other presentation technology. Now, you may be the J2EE programming model also had some doubts. If you wish to further research platform choice, you can in the Apache Cocoon, Enhydra, and various template engine to find an alternative to JSP technology.
Finally, remember, this is not recommended that you use JSP or avoid it, even though the surface like this. My aim is to encourage you to conduct a detailed analysis of any technology to ensure that it is the right choice. As the same programming model, and sometimes they are right, but sometimes they do not fit. Some more more, finds the most suitable technologies and to make informed decisions, rather than a hasty decision.