The struts2 of jsp page empty text box and the different types of action layer judgment __JS

Source: Internet
Author: User
Tags getcolor getdate
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; }



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.