Tip case -- else... If ....

Source: Internet
Author: User

Else... If...

<C: If test = ""> AAA </C: If> -- iftag. Java

<C: else> BBBB </C: else> -- elsetag. Java

Put in parent label

Let the IF and else object processors share a Boolean object to notify the respective label processors whether to execute the following code

<C: Choose> -- choosetag. Java

<C: whentest = "$ {user! = NULL} "> -- whentag. Java

This is my page

</C: When>

<C: Other> -- othertag. Java

If user is not ex

</C: Other>

</C: Choose>

Code:

Choosetag. Java

Private BooleanFlag =False;

// To read the flag value in the subclass, all get methods are required.

Public BooleanIsflag (){

ReturnFlag;

}

Public voidSetflag (BooleanFlag ){

This. Flag = flag;

}

@ Override

Public voidDotag ()ThrowsJspexception, ioexception {

//TodoAuto-generatedmethod stub

Jspfragment JF =This. Getjspbody ();

JF. Invoke (Null);

}

Otherwise. Java section:

Public voidDotag ()ThrowsJspexception, ioexception {

//TodoAuto-generatedmethod stub

// Obtain the parent tag object

Choosetag parent = (choosetag)This. Getparent ();

If(! Parent. isflag ()){

This. Getjspbody (). Invoke (Null);

Parent. setflag (True);

}

}

Whentag. Java

Private BooleanTest;

Public voidSettest (BooleanTest ){

This. Test = test;

}

@ Override

Public voidDotag ()ThrowsJspexception, ioexception {

//TodoAuto-generatedmethod stub

// Parent tag object

Choosetag parent = (choosetag)This. Getparent ();

If(Test &&! Parent. isflag () {// test is true, and no branch has been executed

// Process the TAG body

This. Getjspbody (). Invoke (Null);

Parent. setflag (True);

}

}

Testif. jsp

<% Session. setattribute ("user", "zhangsan"); %>

<Br/> __________________________________ <br/>

<! -- Test the IF and else labels -->

<C: Choose>

<C: When test ="$ {User! = NULL}">Aaaaa</C: When>

<C: otherwise>Bbbbbb</C: otherwise>

</C: Choose>

C. TLD Section

<? XML version ="1.0"Encoding =UTF-8"?>

<! Doctype taglib public "-// sunmicrosystems, Inc. // dtd jsp tag library 1.2 //" http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd ">

<Taglib>

<Tlib-version> 1.0 </tlib-version>

<JSP-version> 1.2 </JSP-version>

<Short-Name> C </short-Name>

<URI> http://www.c.com </uri>

<Tag>

<Name> If </Name>

<Tag-class> com. hbsi. Tag. iftag </Tag-class>

<Body-content>Scriptless</Body-content>

<Attribute>

<Name> test </Name>

<Required> true </required>

<Rtexprvalue> true </rtexprvalue>

</Attribute>

</Tag>

 

<Tag>

<Name> choose </Name>

<Tag-class> com. hbsi. Tag. choosetag </Tag-class>

<Body-content>Scriptless</Body-content>

</Tag>

 

<Tag>

<Name> when </Name>

<Tag-class> com. hbsi. Tag. whentag </Tag-class>

<Body-content>Scriptless</Body-content>

<Attribute>

<Name> test </Name>

<Required> true </required>

<Rtexprvalue> true </rtexprvalue>

</Attribute>

</Tag>

 

<Tag>

<Name> otherwise </Name>

<Tag-class> com. hbsi. Tag. otherwisetag </Tag-class>

<Body-content>Scriptless</Body-content>

</Tag>

</Taglib>

 

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.