- 浏览: 157486 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
acang84n:
难得是2.3的版本注解方式不一样!?
Struts2 注解配置 demo2 -
acang84n:
为什么用struts2-convention-plugin-2 ...
Struts2 注解配置 demo2 -
taney_911:
这个正则表达式也太长了把。。。
Java中正则表达式验证日期格式 -
iamaj2eeprogrammer:
非常感谢你给出的例子!
Struts2 注解配置 demo2 -
superran_sy:
害人。。。
8888-88-88
居然也格式正确
Java中正则表达式验证日期格式
转自处:http://www.vaannila.com/struts-2/struts-2-example/struts-2-ui-tags-example-1.html
搭建好struts2环境
web.xml配置
RegisterAction.java类
Country.java类
struts.xml配置
jsp文件
index.jsp
register.jsp
success.jsp
发布到tomcat后在浏览器中输入
http://localhost:8080/Struts2_UITagsExample/
或
http://localhost:8080/Struts2_UITagsExample/populateRegister.action
即可
附件是完整工程
搭建好struts2环境
web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Struts2_UITagsExample</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
RegisterAction.java类
package com.test; import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private String userName; private String password; private String gender; private String about; private String country; private List<Country> countryList; private String[] community; private List<String> communityList; private Boolean mailingList; public String populate() { countryList = new ArrayList<Country>(); countryList.add(new Country(1, "India")); countryList.add(new Country(2, "USA")); countryList.add(new Country(3, "France")); communityList = new ArrayList<String>(); communityList.add("Java"); communityList.add(".Net"); communityList.add("SOA"); community = new String[] { "Java", ".Net" }; mailingList = true; return "input"; } public String execute() { return SUCCESS; } 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 getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getAbout() { return about; } public void setAbout(String about) { this.about = about; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public List<Country> getCountryList() { return countryList; } public void setCountryList(List<Country> countryList) { this.countryList = countryList; } public String[] getCommunity() { return community; } public void setCommunity(String[] community) { this.community = community; } public List<String> getCommunityList() { return communityList; } public void setCommunityList(List<String> communityList) { this.communityList = communityList; } public Boolean getMailingList() { return mailingList; } public void setMailingList(Boolean mailingList) { this.mailingList = mailingList; } }
Country.java类
package com.test; public class Country { private int countryId; private String countryName; public Country(int id,String name) { countryId = id; countryName = name; } public int getCountryId() { return countryId; } public void setCountryId(int countryId) { this.countryId = countryId; } public String getCountryName() { return countryName; } public void setCountryName(String countryName) { this.countryName = countryName; } }
struts.xml配置
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file="struts-default.xml"/> <package name="com.test" extends="struts-default"> <action name="*Register" method="{1}" class="com.test.RegisterAction"> <result name="populate">/register.jsp</result> <result name="input">/register.jsp</result> <result name="success">/success.jsp</result> </action> </package> </struts>
jsp文件
index.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <META HTTP-EQUIV="Refresh" CONTENT="0;URL=populateRegister.action"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> </body> </html>
register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Register Page</title> </head> <body> <s:form action="Register"> <s:textfield name="userName" label="User Name" /> <s:password name="password" label="Password" /> <s:radio name="gender" label="Gender" list="{'Male','Female'}" /> <s:select name="country" list="countryList" listKey="countryId" listValue="countryName" headerKey="0" headerValue="Country" label="Select a country" /> <s:textarea name="about" label="About You" /> <s:checkboxlist list="communityList" name="community" label="Community" /> <s:checkbox name="mailingList" label="Would you like to join our mailing list?" /> <s:submit /> </s:form> </body> </html>
success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Details Page</title> </head> <body> User Name: <s:property value="userName" /> <br> Gender: <s:property value="gender" /> <br> Country: <s:property value="country" /> <br> About You: <s:property value="about" /> <br> Community: <s:property value="community" /> <br> Mailing List: <s:property value="mailingList" /> </body> </html>
发布到tomcat后在浏览器中输入
http://localhost:8080/Struts2_UITagsExample/
或
http://localhost:8080/Struts2_UITagsExample/populateRegister.action
即可
附件是完整工程
- Struts2_UITagsExample.rar (3.6 MB)
- 下载次数: 40
发表评论
-
java 图片压缩
2013-10-17 14:30 525http://fandayrockworld.iteye.co ... -
java的spring的quartz 时间配置相应字符串的说明与实例
2011-12-15 11:19 972本文源自:http://js.sse6.cn/gzsgfrz/ ... -
Spring事务配置的五种方式
2011-01-19 09:12 754http://www.blogjava.net/robbie/ ... -
log4j.xml配置 分级打印日志和打印到指定文件中
2009-11-26 12:50 4238<?xml version="1.0&qu ... -
Spring启动时出现 ERR=12505 异常
2009-11-26 12:47 1517这是由于,spring配置文件中有数据源配置错误,修改后就可以 ... -
用正则表达式替换手机号码前缀86
2009-11-25 09:24 3855Pattern p2 = Patt ... -
ibatis sqlMapConfig settings 中属性用法
2009-09-28 14:12 5089转自 http://zhangzuanqian.iteye.c ... -
SqlMapException: There is no statement named解决方法
2009-09-28 12:51 5331报如下异常解决方法 sqlMapConfig 里加入 < ... -
关于struts2无法加载struts.properties的问题
2009-09-25 17:52 1322http://blog.chinaunix.net/u/200 ... -
Spring2.5、Struts2、Ibatis2.3开发框架搭建
2009-09-25 17:47 1850Spring2.5、Struts2、Ibatis ... -
Struts2 注解配置 demo2
2009-08-21 17:02 6454http://www.vaannila.com/struts- ... -
Struts2 注解配置 demo1
2009-08-21 16:25 1741from http://www.vaannila.com/st ... -
Struts2 HelloWorld MAX的struts教程的demo
2009-08-20 15:51 1105原文http://www.blogjava.net/max/c ... -
使用Struts2
2009-08-20 14:45 1072原文http://developer.51cto.co ... -
JSP乱码解决 之 pageEncoding和contentType属性,UTF-8 GBK gb2312 详解
2009-07-30 10:14 1463文章来源于志伟教程资 ... -
Tomcat的JNDI配置
2009-07-06 15:53 1461驱动需要拷到tomcat/common/lib/目录 1 we ... -
web应用 xml方式配置
2009-07-06 15:49 744编写一个xml文件,然后放到tomcat目录/conf/Cat ... -
Tomcat类装载器
2009-07-06 15:12 798context.xml: <Context> ... -
解决request.getParameter()中文乱码的问题
2009-02-21 16:52 4947jsp页面中 用click事件调用js 此时的页面编码要用UT ... -
搭建SVN服务端
2009-02-09 11:12 1244转载http://hi.baidu.com/axhack/bl ...
相关推荐
Struts2 UI标签示例(包含tabbedPanel标签,autocompleter标签,tree和treenode,optiontransferselect标签等)
struts2-tags-API.rar
struts2 WebWork 2 标签 tags API 参考文档 参考手册
form,这个属性 引用表单元素所在的表单,通过该form属性,可以实现表单元素和表单之间的交互。例如,我们可以通过${parameters.form.id}来取得 表单元素所在表单的ID。
struts2的标签使用的api,也是在网上下载的,挺好的
struts2 中tags.tld文件,共享使用
NULL 博文链接:https://cdxs2.iteye.com/blog/1938252
在struts2 下 使用jquery-ui的多个基本组件的实例 适合初学着熟悉 struts2 和jquery ui
自己制作的struts2 tags,包括了struts2的所有标准标签。 格式是chm的,希望能对大家有所帮助.
Struts2-Tags.rar ssssssssssssssssss ssssssssssssssssss
struts2-tags-API帮助文档
struts-tags.tld struts-tags.tldstruts-tags.tld struts-tags.tld struts-tags.tld
struts2 CRUD example
struts2标签详细帮助文档,介绍的很详细,每个标签后都有例子!
struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别struts1和struts2的区别...
struts2-tags-API 轻松学习tags标签
Struts 2.0 UI标签 实例程序