Developing efficient Enterprise Dynamic web system

Source: Internet
Author: User
Tags foreach define functions odbc sql net string apache tomcat
web| Dynamic JSP Dynamic Web page technology introduced by many companies such as Sun has been widely popular. It inherits Java's cross-platform, portable, high-performance features, making it superior to Microsoft's ASP in both functionality and security. Many JSP program designers in the use of JSP Dynamic Web site development, recognizing the use of JavaBean technology for functional encapsulation of the importance, but ignored the tag library, the use of the key technology. As we all know, HTML language is a pure markup language, if you want to implement the "Hello" as a red font function, just use <font color= "Red" >Hello</font> on it. So,<font> is a typical tag, and color is its property. Now, the idea is to use a similar marking method to achieve email delivery, but also to define a <sendmail attribute >......</sendmail> tag, and then you can <sendmail ......> Lzwasp@263.net</sendmail> sent a letter to Lzwasp@263.net's mailbox. The tag library refers to the tag libraries for tags such as <sendmai>. It is similar to a function library or component, but differs from both, because it expresses the implementation with a property in a tag and tag. Tag library is the combination of XML technology and JSP products, mainly embodied in the use of tags (tag) to express and realize the function to achieve. Today, most JSP service providers develop JSP engines that support tag library technology, such as the famous Apache Tomcat, IBM's WebSphere, and Bea's WebLogic are typical JSP service platforms. Not only that, these engines also developed a lot of good tags, packaged into tag Library, easy to call developers. Allaire Company launched the JRun in these services platform is a solo show. It has a good performance, but also provides its own tag Library, that is, jruntags. Jruntags can realize many important functions of dynamic Web page design, such as database connection and operation, sending and fetching of email. The following is an example of how to use Jruntags on JRun platform to enhance the development of dynamic Web pages and improve development efficiency.

Application Examples

The example of this article is to allow students to view the course catalogue online, and to conduct online elective courses to enhance the statistics, classification, and reduce the complexity of human operation by computer processing.



Database tables

Use Access to build a database Test.mdb and create a data source name named DB in ODBC to point to the Test.mdb database and use JDBC-ODBC Bridge for database connections. Among them, the database Test.mdb has SUBJECT_TB and STU_SUB_TB two tables, the table structure is as follows.

Subject table:

     
      
       
      field type, Length field type, length course number char (3)        course name Char (20) Teacher char (10) Introduction char (50)
     
      


STU_SUB_TB table:

     
       
        
      field type, Length field type, length learning number char (7) Course number char (3)
     
       


Partial program code:

        
         
inc.jsp<%@ page import= "java.sql.*,allaire.taglib.*"%><%string xh = Request.getparameter ("T2"); String SubID = request.getparameter ("T1"); Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver"). newinstance (); Connection con = drivermanager.getconnection ("jdbc:odbc:db");%>select_sub.jsp<%@ page contenttype= "text/html; charset=gb2312 "%><%@ taglib uri= jruntags" prefix= "JRun"%><%@ include file= "inc.jsp"%><jrun:if Expr= "<%= xh!= null && subID!= null%>" ><jrun:sql connection= "<%= con%>" > INSERT into Stu_ SUB_TB (School number, course number) VALUES (<jrun:sqlparam value= "<%=xh%>"/>,<jrun:sqlparam value= "<%=subid%>"/ > </jrun:sql> you have already selected the course number for <font color= "Red" ><b>[<%=subID%>]</b></font>. </jrun:if><jrun:sql connection= "<%= con%>" id= "RS" > SELECT * from subject_tb</jrun:sql>< Center><b> Elective course </b></center><table width= "100%" ><tr><jrun:paraM id= "rs" type= "QueryTable"/><jrun:foreach item= "field" type= "String" group= "<%= Rs. Names%> "> <td align=" center "><b><%= Field.touppercase ()%></b></td></jrun: Foreach><jrun:form method= "Post" Name= "Form1" ><jrun:foreach group= "page.rs" ><tr><jrun: foreach item= "x" group= "<%= Rs." Values%> "><td align=" center "><%= x%></td></jrun:foreach></tr></jrun: Foreach><td><b> I want to take an elective: </b></td><td><jrun:input name= "T1" value= "course number" class= " Form-input "Size="/></td><td><b> School No. </b></td><td>   < Jrun:input name= "T2" type= "text" size= "ten"/>  <input type= "Submit" Name= "TJ" value= "Submit" ></td& Gt;<td> </td></tr></table></jrun:form>
        




Functions and Fundamentals

As you can see from this instance, the Inc.jsp file is included in the select_sub.jsp, and uri= is invoked by <%@ taglib jruntags "prefix=" JRun "%>". It also defines a prefix jrun similar to the creation of an object, and implements various tokens prefixed with "JRun". <jrun:if......> and <jrun:foreach......> are the if judgments and for loops in program design. The <jrun:sql connection......> is a connection to a database, with all standard SQL operations for SELECT, insert, Del, and so on. These operations are encapsulated in the tag. It can be seen that the use of jruntags is very easy and the code is brief.

The Tag library works also very simple, inseparable from TLD and tei these two kinds of documents. A TLD is a file with a. tld extension that uses standard XML syntax to define tag and tag attributes. The TEI is actually a standard Java file, which declares a variety of methods to handle the tags in the corresponding TLD file. In other words, a complete JSP application system based on tag library consists of three important files such as. jsp,. TLD,. Class (. java). Therefore, the Servers\lib\jruntags.jar file in the JRun installation directory plays an extremely important role in this example, and the Jruntags.jar file is a compressed package that contains taglib.tld and a number of corresponding Tei (. Class) files.

advantages of using Jruntags

A similar point of ASP and JSP is that they all embed explanatory code contained in <%%> in the HTML language. From the select_sub.jsp code can be seen, the application of jruntags to avoid the appearance of <%%> as far as possible, almost achieve the form of pure tag (tag). The advantage of this is that it is more conducive to the division of the Web site development, improve development efficiency, enhance scalability and maintainability. The

Web site development team typically consists of both interface (art) design and dynamic programming. The former is responsible for using HTML language to enhance the visual beauty of the site, while the latter focus on the design process, and the database to deal with, to achieve dynamic call data function. Only the two cooperate with the tacit understanding can develop the function is powerful, the interface is lively and beautiful dynamic website. However, in the application of JSP development, often because the interface designers mistakenly deleted the "<%" or the programmer messed up the table nesting and many other errors and greatly affect the efficiency of development. With the tag Library, functional designers can focus more on the definition and development of tag, which is the realization of functionality, and interface developers can also design vivid pages based on easy to understand tag and HTML language. In this way, both the division of labor is clear, and do not interfere with each other, not only improve efficiency, but also easy to check the wrong.

Jruntags has the above advantages, at the same time, according to the needs of the user's objective to define the most commonly used tag, such as sending and receiving mail, send and receive messages, etc., save the development time of the function designer. The author in the development process also uses the SendMail function, may send the notice and so on the information in time to the student's mailbox. This implementation does not require lengthy code.

Concluding remarks

XML is being progressively applied to a wider range of applications, as well as a JSP with good cross-platform performance. In this way, the tag library based on XML and JSP can also run smoothly on different platforms. Allaire Company also provides the Linux platform under the JRun engine, the author will be developed on the Windows platform JSP program to Linux, without the need to modify any code, can run smoothly. It can be imagined that with the powerful functions of JSP and XML, Jsp+xml technology will be widely used.

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.