struts2标签使用汇总- - JavaEye技术网站

<%@ page language="java" contentType="text/html; charset=UTF-8"
?pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<html>
?<head>
??<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
??<sx:head debug="false" extraLocales="en-us,nl-nl,de-de,zh_CN" />
??<title>注册页面</title>
?</head>
?<body>
??<s:form action="registAction" name="regForm">
???<table width="50%" align="center">
????<tr>
?????<th>
??????用户注册
?????</th>
????</tr>
????<tr>
?????<td>
??????<s:textfield label="用户名" name="username" required="true" />
?????</td>
????</tr>

????<tr>
?????<td>
??????<s:password label="密码" name="password" required="true" />
?????</td>
????</tr>

????<tr>
?????<td>
??????<s:password label="确认密码" name="verifypassword" required="true" />
?????</td>
????</tr>

????<tr>
?????<td>
??????<s:textfield label="注册邮箱" name="email" required="true" />
?????</td>
????</tr>

????<tr>
?????<td>
??????<s:radio label="性别" list="%{#{'0':'男性','1':'女性'}}" name="sex" value="'男性'"></s:radio>
????</tr>

????<tr>
?????<td>
??????<s:select label="住址"
???????list="{'西城区','东城区','朝阳区','海淀区','大兴区','丰台区','通州区','怀柔区'}"
???????name="address" value="'朝阳区'"></s:select>
?????</td>
????</tr>


????<tr>
?????<td>
??????<s:combobox label="职位"
???????list="{'Java开发工程师','前台美工','.net开发工程师','C++工程师','客服人员'}"
???????name="job"/>
????</tr>

????<tr>

?????<td>
??????<s:checkboxlist label="从哪里了解到本公司信息?" name="msgfrom"
???????list="{'报纸','电视','互联网','朋友介绍'}" value="'互联网'" />
?????</td>
????</tr>


????<tr>
?????<td>
??????<!-- 级联菜单标签 -->
??????<s:doubleselect label="业余爱好" name="type" list="{'球类', '棋类'}"
???????doubleName="hobby"
???????doubleList="top == '球类' ? {'篮球', '乒乓球','羽毛球','网球','足球'} : {'象棋', '围棋','陆战棋'}"
???????formName="regForm" />
?????</td>
????</tr>

????<tr>
?????<td>
??????<s:optiontransferselect label="你喜欢的书籍" name="javabook"
???????leftTitle="Java书籍" rightTitle="其它书籍"
???????list="{'Java编程思想', 'JUnit In Action', 'Java核心技术','Hibernate In Action'}"
???????multiple="true" headerKey="headerKey"
???????headerValue="------ 请选择 ------" emptyOption="true"
???????doubleList="{'软件工程', 'C++ Primer', '算法设计','JVM原理'}"
???????doubleName="otherbook" doubleHeaderKey="doubleHeaderKey"
???????doubleHeaderValue="------ 请选择 ------" leftDownLabel="向下移动"
???????leftUpLabel="向上移动" rightDownLabel="向下移动" rightUpLabel="向上移动"
???????addToRightLabel="向右移动" addToLeftLabel="向左移动"
???????addAllToRightLabel="全部右移" addAllToLeftLabel="全部左移"
???????selectAllLabel="全部选中" upDownOnLeftOnclick="true" />
?????</td>
????</tr>

????<tr>
?????<td>
??????<s:select label="户口所在地" name="city" value="%{'北京市'}"
???????list="%{'北京市'}">
???????<s:optgroup label="河南省"
????????list="%{#{'郑州':'郑州','洛阳':'洛阳','安阳':'安阳'}}" />
???????<s:optgroup label="山东省"
????????list="%{#{'青岛':'青岛','大连':'大连','烟台':'烟台'}}" />
???????<s:optgroup label="江西省"
????????list="%{#{'南昌':'南昌','九江':'九江','浔阳':'浔阳'}}" />
??????</s:select>
?????</td>
????</tr>

????<tr>
?????<td>
??????<sx:datetimepicker name="regdate" label="内置日期控件(基于dojo)" value="%{'today'}"
???????displayFormat="yyyy年MM月dd日" />
?????</td>

????</tr>

????<tr>
?????<td align="right">
??????<sx:autocompleter name="fruitlike" label="静态表单自动填充(autocomplete中文问题尚未解决)"
???????list="{'apple','banana','pear','grape'}" autoComplete="true" />
?????</td>
????</tr>

????<tr>
?????<td></td>
?????<td align="right">
??????<input type="submit" value="注册" />
?????</td>
????</tr>
???</table>
??</s:form>
?</body>
</html>

?

接收参数bean

?

package com.song.bean;

/**
?* struts2标签元素获取
?*/
import java.util.ArrayList;
import java.util.List;

public class RegistBean {
?private String username;
?
?private String password;
?
?private String email;
?
?private byte sex;
?
?private String address;
?
?private String job;
?
?private List<String> msgfrom = new ArrayList<String>();
?
?private String hobby;
?
?private String[] javabook;
?
?private String[] otherbook;
?
?private String city;
?
?private String regdate;
?
?private String fruitlike;

?public String getUsername() {
??return username;
?}

?public void setUsername(String username) {
??this.username = username;
?}

?public String getPassword() {
??return password;
?}

?public void setPassword(String password) {
??this.password = password;
?}

?public String getEmail() {
??return email;
?}

?public void setEmail(String email) {
??this.email = email;
?}

?public byte getSex() {
??return sex;
?}

?public void setSex(byte sex) {
??this.sex = sex;
?}

?public String getAddress() {
??return address;
?}

?public void setAddress(String address) {
??this.address = address;
?}

?public String getJob() {
??return job;
?}

?public void setJob(String job) {
??this.job = job;
?}

?public List<String> getMsgfrom() {
??return msgfrom;
?}

?public void setMsgfrom(List<String> msgfrom) {
??this.msgfrom = msgfrom;
?}

?public String getHobby() {
??return hobby;
?}

?public void setHobby(String hobby) {
??this.hobby = hobby;
?}

?public String[] getJavabook() {
??return javabook;
?}

?public void setJavabook(String[] javabook) {
??this.javabook = javabook;
?}

?public String[] getOtherbook() {
??return otherbook;
?}

?public void setOtherbook(String[] otherbook) {
??this.otherbook = otherbook;
?}

?public String getCity() {
??return city;
?}

?public void setCity(String city) {
??this.city = city;
?}

?public String getRegdate() {
??return regdate;
?}

?public void setRegdate(String regdate) {
??this.regdate = regdate;
?}

?public String getFruitlike() {
??return fruitlike;
?}

?public void setFruitlike(String fruitlike) {
??this.fruitlike = fruitlike;
?}
?
}
验证规则

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "">
<validators>
?<field name="username">
??<field-validator type="requiredstring">
???<param name="trim">true</param>
???<message>用户名不能为空!</message>
??</field-validator>
?</field>

?<field name="password">
??<field-validator type="requiredstring">
???<param name="trim">true</param>
???<message>密码不能为空!</message>
??</field-validator>
??<field-validator type="stringlength">
???<param name="trim">true</param>
???<param name="minLength">6</param>
???<message>密码最短${minLength}位!</message>
??</field-validator>
?</field>

?<field name="verifypassword">
??<field-validator type="fieldexpression">
???<param name="trim">true</param>
???<!--
????<param name="expression"> <![CDATA[verifypassword==password]]>
????</param>
???-->
???<param name="expression"><![CDATA[(#parameters.password[0] == #parameters.verifypassword[0])]]></param>

???<message>密码和确认密码不一致!</message>
??</field-validator>
?</field>

?<field name="email">
??<field-validator type="regex">
???<param name="expression"><![CDATA[^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$]]></param>
???<message>你输入的地址不是有效的Email地址!</message>
??</field-validator>
?</field>
</validators>

?

郑重声明:资讯 【struts2标签使用汇总- - JavaEye技术网站】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——