JSP Struts1 Label Example detailed 1th/2 page _jsp programming

Source: Internet
Author: User
Tags tld
1,tagform.java
Copy Code code as follows:

Package com.tarena.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 code 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"%>

<!--need to specify a form bean in the name attribute of the "/tag" path for the action in Struts-config.xml-->
Username:Password:<!--
After the checkbox, add a hidden input box with the same name as the checkbox and value "false", forcing struts to reset the property value of the checkbox
In general, Boolean variables are used in Actionform to represent a checkbox because it is either not selected or is selected.

The Multibox tag generates a check box on a Web page, but it functions as a checkbox.
The difference is that the check box is represented by an array in the Actionform where the check box is located.
Therefore, in general, the recommended use of Multibox.
Private Boolean CheckBox1;
Private string[] Hobbies;
-->
Checkbox1:<input type= "hidden" name= "CheckBox1" value= "false" >
Checkbox2:<input type= "hidden" name= "CheckBox2" value= "false" ><br>

Hobbies:swimReadingWalking
<!--radio from form if the setter has been assigned, the value on the page is equal to the value will be checked-->
Gender:maleFemale
<!--provinces is defined and assigned in the 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"));
-->

<!--
Size is 1, only one option is displayed at the same time.
There is also a multiple property that, when True, allows multiple selections for the select list. The user can drag through the mouse or hold down the CTRL key to select multiple selections.
When the Multiple property is true, the corresponding property in Actionform should be an array type to assign to it the user-selected multiple values at the same time.
-->

<input type= "Submit" value= "register" >
<br><br>


Current 1/2 page 12 Next read the full text
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.