Struts form tag

Source: Internet
Author: User

(1) form tag

Form labels are used to present form elements.

Action string current action submit this form will start action

Enctype attribute of the enctype string form

Method string post form Method

By default, the form tag is displayed as an HTML form in the form field. input fields nested in the form tag are displayed as a table row, each table row consists of two fields, one corresponding to the row label and the other corresponding to the input element. The submit button is displayed as a row spanning two columns of cells.

(2) textfield, password, and hidden labels

 

(3) textarea tag

 

(4) checkbox tag

-------------->

 

 

List, listkey, and listvalue attributes:

----------------------------->

--------------------------->

 

(5) radio tag

 

(5) Select tag

 

(6) checkboxlist tag

 

Code example:

User class:

Package com. LLP. Tag;

Import com. opensymphony. xwork2.actionsupport;

Public class user extends actionsupport {
Private integer userid;
Private string username;
Private string password;
Private Boolean agree;
Private string DESC;
 
Public integer getuserid (){
Return userid;
}
Public void setuserid (integer userid ){
This. userid = userid;
}
Public String GetUserName (){
Return username;
}
Public void setusername (string username ){
This. Username = username;
}
Public String GetPassword (){
Return password;
}
Public void setpassword (string password ){
This. Password = password;
}
Public Boolean isagree (){
Return agree;
}
Public void setagree (Boolean agree ){
This. Agree = agree;
}
Public String getdesc (){
Return DESC;
}
Public void setdesc (string DESC ){
This. DESC = DESC;
}
Public String execute () throws exception {
System. Out. println (this );
Return input;

}
@ Override
Public String tostring (){
Return "User [agree =" + agree + ", DESC =" + DESC + ", password ="
+ Password + ", userid =" + userid + ", username =" + Username
+ "]";
}
 
 
}

 

City:

Package com. LLP. Tag;

Public class city {
Private integer cityid;
Private string cityname;
Public integer getcityid (){
Return cityid;
}
Public void setcityid (integer cityid ){
This. cityid = cityid;
}
Public String getcityname (){
Return cityname;
}
Public void setcityname (string cityname ){
This. cityname = cityname;
}
 
Public City (){

}
 
Public City (integer cityid, string cityname ){
This. cityid = cityid;
This. cityname = cityname;
}
 
}

 

JSP page, form-tag.jsp:

<% @ Page Language = "Java" Import = "Java. util. *, Com. LLP. Tag. City" pageencoding = "UTF-8" %>
<% @ Taglib prefix = "S" uri = "/Struts-tags" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> my JSP 'form-tag. jsp 'starting page </title>
</Head>
<Body>
<%
List city = new arraylist ();
City. Add (New City (11, "AA "));
City. Add (New City (12, "BB "));
City. Add (New City (13, "cc "));

Request. setattribute ("Cities", city );

List city2 = new arraylist ();
City2.add (New City (21, "Aa2 "));
City2.add (New City (22, "BB2 "));
City2.add (New City (23, "CC2 "));

Request. setattribute ("cities2", city2 );

List city3 = new arraylist ();
City3.add (New City (31, "aa3 "));
City3.add (New City (32, "bb3 "));
City3.add (New City (33, "CC3 "));

Request. setattribute ("cities3", city3 );

%>
 
<S: Form Action = "/testformtag" namespace = "/">
<S: hidden name = "userid"> </S: hidden>
<S: textfield name = "username" label = "username"> </S: textfield>
<S: password name = "password" label = "password"> </S: Password>

<! -- Single choice button -->
<S: Radio list = "# {'1': 'male', '0 ': 'female'} "name =" gender "label =" sex "> </S: Radio>

<! -- Drop-down list -->
<S: select list = "# request. Cities" listkey = "cityid" listvalue = "cityname"
Name = "city" label = "city" headerkey = "" headervalue = "select city">
<S: optgroup label = "City 1" list = "# request. cities2" listkey = "cityid" listvalue = "cityname"> </S: optgroup>
<S: optgroup label = "City 2" list = "# request. cities3" listkey = "cityid" listvalue = "cityname"> </S: optgroup>
</S: Select>

<! -- Check box -->
<S: checkboxlist label = "xingqu" name = "interesting"
List = "# {'10': 'Party ', '11': 'reading', '12': 'game', '13': 'shopping'}">
</S: checkboxlist>

<! -- Single region -->
<S: checkbox name = "agree" label = ""> </S: checkbox>
<S: textarea name = "DESC" label = "" rows = "3" Cols = "15"> </S: textarea>
<S: Submit> </S: Submit>
</S: Form>
</Body>
</Html>

Struts. xml configuration

<Action name = "test-form-tag" class = "com. LLP. Tag. User">
<Result name = "input">/form-tag.jsp </result>
</Action>

 

 

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.