A JSP example of a tag library that completes a complex background processing function

Source: Internet
Author: User
Tags log log new set

The Jstl label is a product that Sun takes the lead in working with the Apache community, but it has been an outdated technology since its emergence. Sun's software architect seems to lack the ability to think about technology from a customer's point of view, which is far less than Microsoft's. In terms of labeling technology, its purpose is to make rookie rookie can write JSP, or make the general programmer to write JSP more convenient, better management? Apparently, Sun's idiot architect didn't want to understand the truth (the more it looked at its documentation, the more he thought the guy was a big jerk), and wasted the wit of sun thousands of talented engineers.

As everyone knows, JSP appears to make it easier for programmers to write simple servlet, complex multi-function servlet is not easy to implement in JSP. And JSP want to let rookie write Java dynamic page is not to achieve the purpose, this article, not as asp/php. Spreading the underlying business logic in the JSP is not easy to object organization, but also to code management, very inefficient. This is the reason for the development of JavaBean and labeling technology, and JSTL, its basic customer logic is to help users more easily spread the underlying code on the JSP!? Include database connections?! So this thing is a new technology to achieve the target of backward products, the face of market demand a full slow beat.

The only thing that is of value is its cyclic logic, which is still useful. Just can realize not only it, Struts.logic label is very good one, and do not point to http:/sun.xxxx/core what, in fact Jstl can provide struts:logic can also provide. Actually struts several tag libraries are also logi, a bit of value, beans can also, other HTML is pure and Formbean for the core MVC Vision framework provided. Even so, in terms of practicality, strutslib is still much more useful than sun.

The Struts tag library is not well oriented to the data object, which is its inadequacy, and the HANVA tag is to supplement this deficiency. Combined with the logic Library of struts, the use of Hanva tags can be used to declare and receive variables in the JSP, you can implement a variety of logic, you can directly from the bottom of the persistence of the data object, processing and output-a program is roughly the only thing to do. Special things to special treatment, directly using the tag to call the lower service daemon program to complete most of the functions, can be done.

The following Forum sample removal program is a feature that handles any deletion of table data that implements the Hanvadao interface specification, including the synchronization of its related data records. It receives an object type (ENT), and the ID, to determine whether the object (row record) exists, then judge it's SourceID and ID is consistent (is the main paste or keep abreast), if it is the main paste, it is removed from the paste, otherwise it will only delete the current paste, and then return the original call of a page, if the error, Turn to the errors.jsp page to display an error message.

<entity:present ent= "${param.ent}" oid= "${param.oid}" id= "Thent" nexto= "${header.referer}"
    <%--If the record exists, it inherits the embedded logic, and the record is ident name--%>
   <%--to determine if SOURCID is consistent with ID--%>
   <logic:equal name= "thent" value= "${thent.sourceid}" property= "id"
<%--take all the master and subordinate stickers, the collection named Theobjs--%>
   <entity:entities ent= "${param.ent}" id= "Theobjs" qstr= "Sourceid=${sourceid}"
<%-- Iteration collection content, single named Theobj--%>
    <logic:iterate id= "theobj" name= "Theobjs"
<%-- Delete the object--%>
     <cmd:delete ent= "${param.ent}" target= "${theobj}"/>
    </logic:iterate>
   </entity:entities>
   </logic:equal>
  <logic:notequal name= "thent" value= "${thent.sourceid}" property= "id" >
<%--A single paste to clear the object--%>
   <cmd:delete ent= "${param.ent}" target= "${thent}"/
  </logic:notequal>
 </entity:present>

The end of the tag, the nexto to the caller, so that the small piece of code actually acts as a C role in MVC. If you need to output a breakpoint, you can call Hanva:log to output the live content to the log log. A more complex feature is done. The whole process is actually only done once or two times the access to the database, if it is multiple from the paste, need to get its string, this is possible the second time. Note <entity:entities> label, it enters a condition, can also enter fields option, get a ArrayList string (no vector without synchronization), if not for paging, it can replace Hanva:list, It is also more convenient to use, there is no need to set a Dao.list object first.

I think that's the real use of label technology: Help programmers in the interface clearly and clearly call the background of the processing program, instant noodles to the object of the business logic to create, convenient to hide the logic of the expression layer, rather than become a more complicated page, the heap more difficult to understand the code of a new set of methods.

Relatively speaking, tags file label technology appears more realistic. Like JSP is convenient rookie (still programmers) write a simple servlet, tags tag file is easy to see class on the shivering rookie like write jspjavalet like writing labels; obviously, the simplest variant of the Simpletagsupport, Only it has one body content. Similarly, coding techniques that make full use of class structures are not implemented here.

The JSP development community seems keen to provide local convenience in a local way, but often ignores a larger requirement for customers: To complete all programs in a single standard paradigm in project development. More use of a small technology model in the local convenience, the overall is a more management of a technology, or the programmer to learn a more local-only effective technology. This logic error starts from the Java EE accompanied with the development of Sunjava technology, it seems to be its incurable disease. In the author's opinion, rather than many tricks, as in the core of a drill in the end, and a small range of convenient measures, or have the ability to achieve a good customer. A botched imitation of Microsoft's failure to shoot backward (and also non-mainstream customers) will be the cause of sun's technical eventual defeat.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.