struts2中 jsp頁面 空文字框傳值 及action層不同類型的判斷__js

來源:互聯網
上載者:User
struts2可以自動轉換jsp前台傳來的資訊格式
前台jsp
</pre><pre name="code" class="html"><form action="user_setInfo" method="post">  名字<input type="text" value="" name="name"/><br/>  日期<input type="text" value="" name="date"/><br/>  年齡<input type="text" value="" name="age"/><br/>  顏色1<input type="text" value="" name="color"/><br/>  顏色2<input type="text" value="" name="color"/><br/> 尺寸1 <input type="text" value="" name="size"/><br/>  尺寸2<input type="text" value="" name="size"/><br/>  <input type="submit" value="提交"/>  </form>


後台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);System.out.println("日期*****"+date);System.out.println("顏色*****"+color.get(0)+"*****"+color.get(1));System.out.println("尺寸*****"+size[0]+"****"+size[1]);System.out.println("年齡******"+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;}public 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">提交後輸出
</pre><pre name="code" class="java"><img src="https://img-blog.csdn.net/20151107124451402?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />




struts2當前台空文字框時 後台action的拍段,不同類型不一樣


1.當前台jsp中 input 的那麼中 沒有後台action的屬性名稱,除int類型外 則接受到判斷用 xx==null,int類型用xx==0

2 . 當name和action中屬性名稱匹配時

      

  

<span style="color:#ff0000;">//為對象(除Object外)時用xx==null//當為String或Object時用xx.equls("")//當為int時用 xx==0</span>private String name;private Date date;//date==nullprivate List<String> color;//color.get(0).equals("")private Object [] size;//oject 使用equals("")private int age;//age==0public String setInfo() {System.out.println("名字*****"+name.equals(""));System.out.println(date==null);System.out.println(color.get(0).equals(""));System.out.println("顏色"+color);System.out.println(size[0].equals(""));System.out.println("大小"+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");//雖然date為null但是會調用this.date = date;}public List<String> getColor() {return color;}public void setColor(List<String> color) {this.color = color;}public 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;}



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.