Friday, October 8, 2010

I think the JSP problem (on)



(Editor's Note: the original version of this article first appeared in a foreign country, JSP is only one kind of technology was emerging, and this appears to be rising as it is now. Now it seems some of the views of this article may have some limitations, But I have to admit that this is a very atmospheric work, which involves many internal principles of JSP. So, I think it is necessary to introduce to you this article to you from another perspective, a better understanding of JSP technology. )

Now every developer using servlets know JSP, a kind of building on top of the servlet technology invented by Sun and spend a lot of energy to the implementation of web technology. JSP to servlet in the html code out of them, which can speed up application development and web page maintenance. In fact, the official release from the Sun, "Application Development Model" document on the right farther: "JSP technology should be regarded as standard, while servlets in most cases can be considered as a supplement. "

This article will compare the JSP and servlets technology on the other: template engines (template engine).

The problem directly with Servlets

When Servlets been invented, the whole world to see its advantages. Servlet-based dynamic web page can be quickly implemented to allow for easy transfer between multiple servers and can be seamlessly integrated and database, it is widely accepted as a kind of Servlets web server platform of choice.

However, usually can be achieved by simple means html code to now allow programmers out.println () call to each line HTML line, which in the actual Servlet application to become a serious problem. HTML content had to be achieved through the code, which for large HTML page is nothing more than an onerous and time-consuming work. In addition, the staff responsible for Web content developers have requested to carry out all the updates. To this end, the search for this a better solution.

JSP birth

JSP 0.90 was born. In this technique you can embed Java code to the HTML file, the server automatically as the page to create a Servlet. JSP is considered a way to write a simple Servlet. All HTML can be without going through the out.println () call, the staff responsible for the content of the page can modify the HTML and Java code without taking the risk of damage.

However, having artists and developers working on the same file is not ideal, so that embedded HTML Java proved to be just like the HTML embedded in Java as embarrassing. Read a bunch of messy code remains a difficult task.

So, people are becoming mature in the use jsp, greater use of JavaBeans. Beans contain the business logic required jsp code. JSP Most of the code can be taken out into the bean and going, leaving only the few markers for calling bean.

Recently, people began to think this way the JSP page is really very much like a view (view). They become a client requests the results used to display components. So people will think, why not send the request directly to view it? Objective view, if the request inappropriate? After all, a lot of requests for a variety of possible views to get the results view. For example, the request may have the same success page, a database exception error report, or the lack of parameters of the error report. The same request may have an English page may be Spanish pages, depending on the client's locale. Why does the client must send the request directly to the view? Why should not the client requests sent to a number of common server components and allow the server to determine the JSP view of the return?

This makes a lot of people accept has been called "Model 2" design, which is defined in the JSP 0.92 based on model-view-controller model. In this design, the request is sent to a servlet controller, it performs the business logic and data to produce a similar "model" to for display. This data is then sent through an internal JSP "view" to be displayed, so that looks like a normal JSP page embedded in the JavaBean. Responsible for the control of the servlet according to the internal logic to select the appropriate JSP page to display. This, JSP file into a nice template view. This is another development, and is being praised by some other developer has.

Into the Template Engines

If you use a template engine instead of the usual purpose of the JSP, the design goes on will become simple, the syntax simpler, more readable error messages, tools, and more customization. Some companies have done this engine, the most famous may be WebMacro, their engine is free of charge.

Developers should understand, select a template engine to replace the JSP provides the following technical advantages, which also is the inadequacy of jsp:

Problem # 1: Java code template of a too

Although the design is considered bad, JSP Java code is still trying to join the web page. Here are some like Java have done, namely, simplified C + +, modify, template engines also through jsp in the lower layer of the source removed to make simplified. The Template engines to implement a better design.

Problem # 2: Request to write Java code

Required in the JSP page write Java code. For example, suppose a page to determine the root of the current web application context to guide their home, the best in the JSP using the following Java code:

Home page

You can try to avoid the Java code, the use of tags, but this will give you a string of difficult to read as follows:

/ Index.html "> HomePage

Use template engine is no Java code and ugly syntax. This is the same request in written in WebMacro:

Home page

In WebMacro in, ContextPath $ Request variable as a property, use syntax similar to Perl. Other template engines use the syntax of other types.

Look at another example, suppose an advanced "view" needs to set a cookie to record the user default color scheme - a task looks around, not only by the view servlet controller. To have this in the JSP in the Java code:

In WebMacro in no Java code:

# Set $ Cookie.colorscheme = "blue"

As a final example, if, again, get back in the original color profile cookie. For the JSP, we can consider that there is a corresponding utility class to provide help because with getCookies () directly so that lower level become ridiculous and difficult. In the JSP in:

In WebMacro not on the tools need to, usually:

$ Cookie.colorscheme.Value

The need to write jsp graphical interface designers, which grammar is easier to learn?

JSP 1.1 introduces the custom tag (custom tags) and to allow arbitrary HTML tags similar to the background in the JSP page implementation of Java code, which will have some value, but only known to have a broad, full-featured, can obtain free, standardized tag library. There is no such a tag library.







Recommended links:



System Maintenance Evaluation



Harvest autumn HARVEST eMEX Internal Security Code



Ping command usage



News about Office Suites And Tools



CATALOGS Office Suites And Tools



AVI TO MPEG4



Utilize all practical use of Small floating window all captures Thunder 5.9



Internal OUTSOURCING Yijianshuangdiao



MPG to Flash



Foreign Trade before sending samples: judgments, proofing and expenses



Best Pc Registry Cleaners Reviewed Finding The



Pressure direct sales model, "Yang Shuai" Miller came to power Dell



Best Science - Screen Savers



Farewell babyface, iSee 1 minute to create Face-lift effect



VOB To Flash



No comments:

Post a Comment