当前位置: 编程技术>java/j2ee
jsp struts1 标签实例详解第1/2页
来源: 互联网 发布时间:2014-10-17
本文导语: 1,TagForm.java 代码如下: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[] hobbi...
1,TagForm.java
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
userName:
password:
checkbox1:
checkbox2:
hobbies:swim
reading
walking
gender:male
female
Show Value1
Show Value2
Show Value3
代码如下:
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
代码如下:
userName:
password:
checkbox1:
checkbox2:
hobbies:swim
reading
walking
gender:male
female
Show Value1
Show Value2
Show Value3