Details of JSP struts1 tag instances page 1/2

Source: Internet
Author: User
Tags tld

1. tagform. Java CopyCode The Code is as follows: Package com.tar Ena. Struts. Tag. form;

Import org. Apache. Struts. Action .*;
Import javax. servlet. http .*;
Import java. util .*;

Public class tagform extends actionform
{
Private int ID;
Private string username;
Private string password;
Private int sex;
Private string [] hobbies;
Private string from;
Private string introduction;
Private collection provinces;
Private Boolean checkbox1;
Private Boolean checkbox2;

Public tagform ()
{
Sex = 1;
Provinces = new arraylist ();
Provinces. Add (New optionbean ("Beijing", "100000 "));
Provinces. Add (New optionbean ("Hebei", "110000 "));
Provinces. Add (New optionbean ("Tianjin", "120000 "));
}

Public String getfrom ()
{
Return from;
}

Public void setfrom (string from)
{
This. From = from;
}

Public String [] gethobbies ()
{
Return hobbies;
}

Public void sethobbies (string [] hobbies)
{
This. Hobbies = hobbies;
}

Public int GETID ()
{
Return ID;
}

Public void setid (int id)
{
This. ID = ID;
}

Public String getintroduction ()
{
Return introduction;
}

Public void setintroduction (string Introduction)
{
This. Introduction = introduction;
}

Public String GetPassword ()
{
Return password;
}

Public void setpassword (string password)
{
This. Password = password;
}

Public int getsex ()
{
Return sex;
}

Public void setsex (INT sex)
{
This. Sex = sex;
}

Public String GetUserName ()
{
Return username;
}

Public void setusername (string username)
{
This. Username = username;
}

Public Collection getprovinces ()
{
Return provinces;
}

Public void reset (actionmapping mapping, javax. servlet. http. httpservletrequest request)
{
// Checkbox1 = false;
// Hobbies = NULL;
}

Public Boolean ischeckbox1 (){
Return checkbox1;
}

Public void setcheckbox1 (Boolean checkbox1 ){
This. checkbox1 = checkbox1;
}

Public Boolean ischeckbox2 (){
Return checkbox2;
}

Public void setcheckbox2 (Boolean checkbox2 ){
This. checkbox2 = checkbox2;
}

Public void setprovinces (Collection provinces ){
This. Provinces = provinces;
}
}

2, input_struts.jsp copy Code the code is as follows: <% @ page Language =" Java "contenttype =" text/html; charset = UTF-8 "%>
<% @ taglib uri ="/WEB-INF/resource/struts-logic.tld "prefix =" logic "%>
<% @ taglib uri =" /WEB-INF/resource/struts-bean.tld "prefix =" Bean "%>
<% @ taglib uri ="/WEB-INF/resource/struts-html.tld "prefix =" html "%>
<% @ taglib uri = "/WEB-INF/resource/struts-tiles.tld" prefix = "tiles" %>
<% @ taglib uri = "/WEB-INF/resource/struts-nested.tld" prefix = "nested" %>
<% @ taglib uri = "/WEB-INF/resource/C. TLD "prefix =" C "%>
<% @ taglib uri ="/WEB-INF/resource/app. TLD "prefix =" app "%>
<% @ taglib uri ="/WEB-INF/resource/FMT. TLD "prefix =" FMT "%>

<! -- You need to specify a form bean in the name attribute whose path of action is "/Tag" in the struts-config.xml -->
<HTML: Form Action = "/Tag">
<HTML: hidden property = "ID"/>
Username: <HTML: Text property = "username"/>
Password: <HTML: Password property = "password"/> <br>
<! --
Add a hidden input box with the same name as the checkbox attribute and the value is "false" after the checkbox, and force struts to reset the checkbox attribute value.
In general, the actionform uses a Boolean variable to represent a checkbox, because it is either not selected or selected.

The multibox tag generates the check box on the webpage. In fact, it has the same function as the checkbox.
The difference is that an array is used in the actionform where the check box is located to represent the check box.
Therefore, multibox is generally recommended.
Private Boolean checkbox1;
Private string [] hobbies;
-->
Checkbox1: <HTML: checkbox property = "checkbox1"/>
<Input type = "hidden" name = "checkbox1" value = "false">
Checkbox2: <HTML: checkbox property = "checkbox2"/>
<Input type = "hidden" name = "checkbox2" value = "false"> <br>

Hobbies: Swim <HTML: multibox property = "hobbies" value = "1"/>
Reading <HTML: multibox property = "hobbies" value = "2"/>
Walking <HTML: multibox property = "hobbies" value = "3"/> <br>

<! -- Radio sent from form. If setter has been assigned a value, values equal to the value on the page will be checked. -->
Gender: male <HTML: Radio property = "sex" value = "1"/>
Female <HTML: Radio property = "sex" value = "2"/> <br>

<! -- Provinces defines and assigns values in form bean as follows:
Private collection provinces;

Provinces = new arraylist ();
Provinces. Add (New optionbean ("Beijing", "100000 "));
Provinces. Add (New optionbean ("Hebei", "110000 "));
Provinces. Add (New optionbean ("Tianjin", "120000 "));
-->
<HTML: Select Property = "from">
<HTML: optionscollection property = "provinces"/>
</Html: Select>

<! --
If the size is 1, only one option is displayed.
There is also a multiple attribute. When this attribute is set to true, this selection list allows multiple selections. You can drag the mouse or press Ctrl to select Multiple widgets.
When the multiple attribute is true, the corresponding attribute in actionform should be an array type so that multiple values selected by the user can be assigned at the same time.
-->
<HTML: Select Property = "from" size = "3" multiple = "true">
<HTML: option value = "value1"> show value1 <HTML: option value = "value2"> show value2 <HTML: option value = "value3"> show value3 </Html: Select> <br>

<HTML: textarea rows = "5" Cols = "30" property = "Introduction"> <Input type = "Submit" value = "register">
<Br>

</Html: Form>

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.