Java Tag Library (core, xml,sql, internationalization, functions)

Source: Internet
Author: User
Tags tag name xslt tld

The Java Tag Library is divided into the above several, generally used is the core and functions, the next will explain the various, and common usage.

The General tag library is used with the El expression, so the use of the El expression is also studied before learning the tag library.

Expand after import

The corresponding tag library can be viewed from the jar package for the TLD document, which describes the description and usage of each label

Start with the core tag library first

The TLD document has several key points, the first one being the URI, which is the URI when the tag library is introduced into the JSP page

A basic TLD document has so much to focus on, it's not really hard to see apart

1 <% @taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>

Use this tag in the JSP page header to import the tag library, which corresponds to the uri,prefix identifier in the TLD document

1 <jsp:usebean id= "UserBean"  class= "Bean.userbean" scope= "page" ></jsp:useBean> <!--Create an entity bean--2 <c:set target= "${userbean}" property= "name" > Aloof and Pale Wolf </c:set>3 Get Properties: <jsp:getproperty property= "name" name= "UserBean"/>4 <!--The entity Bean is assigned using the SET tag in the core tag library--

Jsp:userbean uses the JSP built-in tag library to instantiate an entity class and deposit it into the page field (the default page), assigning and taking values using the set label of the core tag Library of the C alias

Target object to be assigned, remember to use the EL expression, corresponding to the ID name above, the property name of the object to be assigned value

Remember that the objects and values in the tag library are basically stored in the domain, and the default is page.

The name of the object to be evaluated using the GetProperty tag Name property to go to value

<c:remove var= "UserBean"/><!--the name of the object to remove, do not use the EL Expression--and <c:CatchVar= "ErrorInfo" ><!--catch exception, VAR exception information Object--<jsp:getproperty property= "name" name= "UserBean"/> &LT;/C:Catch> <!--exception info get-Exception:<c:out value= "${errorinfo}"/><br/>Exception Errorinfo.getmessage:<c:out value= "${errorinfo.message}" ></c:out><br/>Exception Errorinfo.getcause:<c:out value= "${errorinfo.cause}" ></c:out><br/>Exception Errorinfo.getstacktrace:<c:out value= "${errorinfo.stacktrace}" ></c:out> <c:iftest= "${errorinfo ne null}" var= "Resutl" scope= "page" >Results<c:out value= "${resutl}" ></c:out> </c:if>
<c:set var= "score" value= "0" ></c:set>        <c:choose>        <!--when the value of test is true---            <c : When test= "${score>=90" > Awesome </c:when>            <c:when test= "${score>=70}" > Yes </c:when>            <!--Other things--            <c:otherwise> weak chickens </c:otherwise>        </c:choose>
<c:out value= "Begin position, items= object to loop, var= each element end position, step increment varstatus current Information" ></c:out><br/>        <c:foreach var= "va" items= "${list}" begin= "0" end= "5" step= "2" varstatus= "S" >                     Value:<c:out Value= "${va}"/> subscript                     :<c:out value= "${s.index}"/>                    <c:out value= "${s.first}"/ >                    <c:out value= "${s.last}"/>        <br/>        </c:forEach>

The core tag libraries are often used so much that others can view the TLD

Function Tag Library

<% @taglib uri= "http://java.sun.com/jsp/jstl/functions" prefix= "FN"%>

Convert uppercase

function tags can only be written in the El expression, most of the processing of strings, such as the format of the array, retrieving indexof, etc.

XML Tag Library

1 2         <c:import url= "http://localhost:8080/jspStudey/ Test.xml "var=" BookInfo "/>3         <c:import url=" Http://localhost:8080/jspStudey/test.xsl " Var= "XSLT"/>4         <x:parse xml= "${bookinfo}" var= "Output"/>5          <%--<x:out select= "$output/books/book[1]/name"/>--%>6          <x:transform xml= "${bookinfo}" xslt= "${xslt} "/>

Imports XML using import, which is processed using X:parse. Xml=xml Resource object var= processed XML object

X:out The value output is similar to the core out, after the XML processing to output can only use this output select query, the first $ (no parentheses) processing good var/split root node name/Sub-section name

SQL Tag Library

1<sql:setdatasource var= "Con"2Driver= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"3Url= "Jdbc:sqlserver://localhost:1433;databasename=work" user= "sa" password= "Sasa"/>4<sql:query var= "Result" datasource= "${con}" >select * from stu;</sql:query>5<c:foreach var= "Row" items= "${result.rows}" >6<c:out value= "${row.stuid}" ></c:out>7<c:out value= "${row.stuname}"/>8</c:forEach>9<%--<sql:update datasource= "${con}" var= "result" >insert into Stu values (1006, ' Gaoxiao2 ', 20,80); </sql: Update>--%>Ten<c:set var= "empId" value= "1003" ></c:set> One<sql:update datasource= "${con}" var= "Count" > ADelete from Stu where stuid=?; -<sql:param value= "${empid}"/> -</sql:update> the<c:iftest= "${count eq 0}" > did not delete data </c:if> -</body>

I am learning SQL Tag Library is very puzzled, the amount still feel like writing SQL statements on the JSP very uncomfortable very dislike

Setdatasource Setting the data source var= data source object name  driver= driver Class  url= Connection statement user= database user name password= password it uses SQL Server different databases and versions.
Query Query statement datasource= data Source name intermediate queries
And then loop out the other look at the code should see the


International Word Tag Library
I think this will be more troublesome, will tell the details of the point

SRC under the resource file in the package, the last one is a template file, it is important. The name of the other file must be the template filename _ country name. Properties This is the rule, because the mechanism of the search

The system will retrieve the file under the resource bundle, specify the template file name, and then according to the current country name, for example, China en, then it will be in the template name after the home _ underline and then add the country name,

And then go to retrieve the file with the filename.

Contents of the file: In the form of a key-value pair

JSP use

1<%2     //Request.getlocale () get access to the country where the user is located3ResourceBundle myresourcesbundle=resourcebundle.getbundle ("Myproperties.myproperties", Request.getlocale ());4%>5<body>6<form>7<%=myresourcesbundle.getstring ("username")%>: <%=myresourcesbundle.getstring ("password")%>8</form>9 Ten<fmt:setbundle basename= "myproperties.myproperties" var= "bundle"/> One<fmt:message bundle= "${bundle}" key= "username" ></fmt:message>: <fmt:message bundle= "${bundle}" key= " Password "></fmt:message>

First put on the code, in detail, the front is a small script, followed by the FMT internationalization tag library to write, tag library is like this, put things in class, and on the JSP page refinement, so that the JSP becomes very concise

The small script first gets the current country name and then 2 parameters, the path of a template file for a resource, stored under the SRC root, the second is the country name, and then will automatically go to find him the file, in the name can get the corresponding value

The tag library is simpler and can be obtained directly after specifying a name.

Note is the resource file, the Chinese to transcode, the JDK has the tool can be transcoded, Native2ascii.exe can use this query corresponding to the Ascall code

Almost so, the tag library is not very difficult, the main thing is to see the El expression and TLD documents, if you understand the basic use of the problem. And it can be a lot easier to customize the tag library later.

It's almost 1 o'clock, and the first blog is almost over. Send my teacher A word, take doctrine, sharing spirit.

Java Tag Library (core, xml,sql, internationalization, functions)

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.