Struts2 can automatically convert the information format from the JSP foreground
Front JSP
</pre><pre name= "code" class= "HTML" ><form action= "User_setinfo" method= "POST" >
name <input Type= "text" value= "" name= "name"/><br/>
date <input type= "text" value= "" name= "date"/><br/>
ages <input type= "text" value= "name=" age "/><br/>
color 1<input type=" text "value=" "name=" Color " ><br/>
Color 2<input type= "text" value= "name=" color "/><br/>
size 1 <input type=" text " Value= "" "Name=" size "/><br/>
size 2<input type=" text "value=" "name=" size "/><br/>
< Input type= "Submit" value= "submitted"/>
</form>
Background action
Package action;
Import Java.util.Date;
Import java.util.List;
Import Javax.servlet.http.HttpServletRequest;
Import Org.apache.struts2.ServletActionContext;
Import Com.opensymphony.xwork2.ActionSupport;
public class Useraction extends actionsupport{/** * 952740499/private static final long serialversionuid = 1L;
private String name;
private date date;
private list<string> color;
Private String [] size;
private int age;
Public String SetInfo () {System.out.println ("name * * *" +name);
SYSTEM.OUT.PRINTLN ("Date * * *" +date);
SYSTEM.OUT.PRINTLN ("Color * * * *" +color.get (0) + "* * *" +color.get (1));
SYSTEM.OUT.PRINTLN ("Size * * * *" +size[0]+ "* * * * * * * * +size[1]);
System.out.println ("Age of +age");
return "info";
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
Public Date getDate () {return date;
public void setdate (date date) {this.date = date; Public list<string> GetColor () {return ColoR
public void SetColor (list<string> color) {this.color = color;
String[] GetSize () {return size;
public void SetSize (string[] size) {this.size = size;
public int getage () {return age;
public void Setage (int age) {this.age = age;
}
}
</pre><pre name= "code" class= "Java" > Submit output
</pre><pre name= "code" class= "java" >
Struts2 the background action segment when the current empty text box is different
1. The current table JSP in the input so there is no background action of the property name, in addition to the type of int is accepted to judge by Xx==null,int type with xx==0
2. When the property name in the name and action matches
<span style= "color: #ff0000;"
>//to object (except object) when using Xx==null//When String or object with Xx.equls ("")//when int, with xx==0</span> private String name; Private Date Date;//date==null Private list<string> color;//color.get (0). Equals ("") private Object [] Size;//ojec
T uses equals ("") private int age;//age==0 public String setInfo () {System.out.println ("name * * *" +name.equals (""));
System.out.println (Date==null);
System.out.println (Color.get (0). Equals (""));
SYSTEM.OUT.PRINTLN ("color" +color);
System.out.println (Size[0].equals (""));
SYSTEM.OUT.PRINTLN ("size" +size);
System.out.println (age==0);
return "info";
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
Public Date getDate () {return date;
public void setdate (date date) {System.out.println ("ddddddddddddddddddd");//Although date is null but will call this.date = date;
Public list<string> GetColor () {return color; } public void SetColor (list<string> color) {this.color = color;
Object[] GetSize () {return size;
public void SetSize (object[] size) {this.size = size;
public int getage () {return age;
public void Setage (int age) {this.age = age; }