zoukankan      html  css  js  c++  java
  • Struts2标签之<s:select>

    根据MVC设计模式,JSP页面是不能直接访问的,而是需要通过Servlet或者Struts2中的action进行跳转访问;

    <s:select>标签的内容并不能像HTML一样,直接在页面中设置,而是需要通过读取Action的属性来进行设置;

    在HTML中,代码如下:

        <form>
        	<select name="name">
        		<option value="v1">v1</option>
        		<option value="v2">v2</option>
        	</select>
        </form>

    而在Struts2中,<s:select>的流程如下:



    Action:

    public class ConfigCustomerInfoAction extends ActionSupport {
    	private List<CustomerInfo> typeList = new ArrayList<CustomerInfo>();
    	public String execute()throws Exception{
    		CustomerInfo info1 = new CustomerInfo();
    		info1.setTypeName("normal");
    		info1.setTypeValue("普通用户");
    		typeList.add(info1);
    		CustomerInfo info2 = new CustomerInfo();
    		info2.setTypeName("special");
    		info2.setTypeValue("会员用户");
    		typeList.add(info2);
    		return SUCCESS;
    		
    	}
    	public List<CustomerInfo> getTypeList() {
    		return typeList;
    	}
    	public void setTypeList(List<CustomerInfo> typeList) {
    		this.typeList = typeList;
    	}
    }
    

    struts.xml

    <action name="configCustomerInfo" class="org.xiazdong.action.ConfigCustomerInfoAction">
    	<result>/fillCustomerInfo.jsp</result>
    </action>
    vo

    package org.xiazdong.vo;
    
    public class CustomerInfo {
    	private String typeName;
    	private String typeValue;
    	public String getTypeName() {
    		return typeName;
    	}
    	public void setTypeName(String typeName) {
    		this.typeName = typeName;
    	}
    	public String getTypeValue() {
    		return typeValue;
    	}
    	public void setTypeValue(String typeValue) {
    		this.typeValue = typeValue;
    	}
    	
    }
    JSP
    <s:select list="typeList" name="type" listKey="typeName" listValue="typeValue" label="用户类型"></s:select>

    注意点:

    (1)各种getter和setter方法都要有,毕竟Struts2框架就是依靠反射的。



  • 相关阅读:
    运用VS制作安装包
    return的总结
    Swift UIAlertController、UISegmentedControl
    Swift 菊花、UIPageControl和UIProgressView
    Swift UITextField各种属性的设置
    Swift 发送邮件和发短信
    Swift GCD
    swift 定义枚举和结构体 及使用
    iOS怎么来实现关闭自动锁屏
    IOS开发 清空数组正确方法
  • 原文地址:https://www.cnblogs.com/xiazdong/p/3058054.html
Copyright © 2011-2022 走看看