The text is too long. The ellipsis is used to indicate that the title is too long and the ellipsis is used.

Source: Internet
Author: User
Tags tld

Heardytag. TLD

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype taglib public "-// Sun Microsystems, Inc. // dtd jsp tag library 1.1 // "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> <br/> <taglib> <br/> <tlibversion> 1.0 </tlibversion> <br/> <jspversion> 1.1 </jspversion> <br/> <shortname> page </shortname> <br/> <tag> <br/> <Name> Hello </Name> <br/> <tagclass> heardy. mytag </tagclass> <br/> <bodycontent> JSP </bodycontent> </P> <p> <attribute> <br/> <Name> maxleng Th </Name> <br/> <required> false </required> <! -- Whether the attribute is optional --> <br/> <rtexprvalue> true </rtexprvalue> <! -- Whether to accept JSP expression computing results --> <br/> </attribute> <br/> </Tag> <br/> </taglib>

 

Mytag. Java

Package heardy; </P> <p> Import Java. io. ioexception; </P> <p> Import javax. servlet. JSP. jspexception; <br/> Import javax. servlet. JSP. jspwriter; <br/> Import javax. servlet. JSP. tagext. bodytagsupport; <br/> Import javax. servlet. JSP. tagext. tagsupport; </P> <p> public class mytag extends bodytagsupport {<br/>/** <br/> */<br/> Private Static final long serialversionuid = 167634601069545267l; <br/> private string maxlength = "10"; <br/> private string Info; </P> <p> Public String getmaxlength () {<br/> return maxlength; <br/>}</P> <p> Public void setmaxlength (string maxlength) {<br/> This. maxlength = maxlength; <br/>}</P> <p> Public String getinfo () {<br/> return Info; <br/>}</P> <p> Public void setinfo (string info) {<br/> this.info = Info; <br/>}</P> <p> @ override <br/> Public int doendtag () throws jspexception {<br/> jspwriter out = pagecontext. getout (); // The pagecontext object to be initialized by the container <br/> try {<br/> out. print (getinfo (); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}< br/> return tagsupport. eval_page; // process other page content </P> <p >}</P> <p> @ override <br/> Public int dostarttag () throws jspexception {<br/> try {<br/> pagecontext. getout (). print (""); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}< br/> return tagsupport. eval_body_again; // The tag starts to process the content of the tag pair </P> <p >}</P> <p> @ override <br/> Public int doafterbody () throws jspexception {<br/> If (bodycontent. getstring (). length ()> integer. parseint (getmaxlength () <br/>. trim () <br/> setinfo ("<Div Title =/" "<br/> + bodycontent. getstring () <br/> + "/"> "<br/> + bodycontent. getstring (). substring (0, <br/> integer. parseint (getmaxlength (). trim () + "... </div> "); <br/> else {<br/> setinfo (" <div> "+ bodycontent. getstring () + "</div>"); <br/>}< br/> return tagsupport. skip_body; <br/>}</P> <p >}< br/>

 

Index. jsp

<% @ Page Language = "Java" pageencoding = "UTF-8" %> <br/> <% @ taglib uri = "/WEB-INF/heardytag. TLD "prefix =" heardy "%> <br/> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> my JSP 'index' starting page </title> <br/> <meta http-equiv = "Pragma" content = "no-Cache"> <br/> <meta http- equiv = "cache-control" content = "no-Cache"> <br/> <meta http-equiv = "expires" content = "0"> <br/> <Meta HTTP-equiv = "keywords" content = "keyword1, keyword2, keyword3 "> <br/> <meta http-equiv =" Description "content =" this is my page "> <br/> </pead> <br/> <body> <br/> <peardy: hello maxlength = "5"> after </peardy: Hello> <br/> <peardy: Hello maxlength = "10"> afterafterafterafterafter </peardy: hello> <br/> <peardy: Hello maxlength = "5"> This is a long clip. </peardy: Hello> <br/> <peardy: hello maxlength = "5"> AF </peardy: Hello> <br/> </body> <br/> </ptml> <br/>

 

 

You can choose not to specify the maxlength. The default value is 10.

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.