struts2中 jsp页面 空文本框传值 及action层不同类型的判断
来源:互联网 发布:淘宝号申请免费注册 编辑:程序博客网 时间:2024/05/21 09:23
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="http://img.blog.csdn.net/20151107124451402?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
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;}
1 0
- struts2中 jsp页面 空文本框传值 及action层不同类型的判断
- Struts2中Action获取JSP页面传参的方法,及Action获取request的每个方法的区别
- struts2中Action的各项默认值及使用Action直接转发jsp页面
- Struts2 Action中传List值到jsp页面
- struts2开发中在jsp页面中用js取得action中传过来的值
- struts2开发中在jsp页面顶用js取得action中传过来的值
- Struts2 jsp页面和Action之间的传值方式
- struts2 action中获取jsp页面的参数的方法
- struts2 action中获取jsp页面的参数的方法
- struts2中 action获取jsp页面的参数的方法
- struts2中JSP页面给action类赋值的问题
- struts2中jsp页面传值到action的两种方式
- jsp页面判断获得action传的list的是否为空或者list.size的长度
- Struts2 后台action接收 jsp页面中checkbox中的值
- struts2中action获取jsp页面参数
- Struts2中Action获取Jsp页面信息
- 用struts2框架中iframe对应的jsp页面的不到action的值
- Jquery中判断input文本框的值为空
- WPF基础到企业应用系列6——布局全接触
- ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法
- OkHttp解析系列-开篇
- Map<K,V>
- 数组的输出
- struts2中 jsp页面 空文本框传值 及action层不同类型的判断
- 分解质因数
- manacher算法详解
- hdu 1171 Big Event in HDU (01背包)
- [LeetCode] H-Index
- Linux Scheduling Domains
- hdu 2037 今年暑假不AC
- CCPC 2015 A题
- html5兼容IE