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框架就是依靠反射的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值