Struts 2 + Spring 2 + JPA + AJAX示例

这个例子其实就是来自Struts 2的文档,但是原例子针对的是Struts 2.0版本。鉴于Struts2.1 版本不再推荐使用Dojo的plugin,这个例子要在Struts 2.16下跑起来颇费功夫,关于dojo plugin的部分许多都要改。

原文见:[quote]http://struts.apache.org/2.1.6/docs/struts-2-spring-2-jpa-ajax.html[/quote]

如果你下载了struts-all,那么也可以在这里找到(根据自己机器路径相应修改):[quote]file:///D:/struts-2.1.6-all/struts-2.1.6/docs/docs/struts-2-spring-2-jpa-ajax.html[/quote]

关于Struts 2.1不再推荐使用dojo plugin的声明:
[img]http://dl.iteye.com/upload/picture/pic/44085/490b6449-8172-3a47-be1a-5b00048e4fbe.jpg[/img]

关于数据库创建语句,原文是这样:[code]CREATE TABLE 'quickstart'.'Person' (
'id' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
'firstName' VARCHAR(45) NOT NULL,
'lastName' VARCHAR(45) NOT NULL,
PRIMARY KEY('id')
)
ENGINE = InnoDB;[/code]
这样是错的,需要把单引号改为‘号(数字1左边那个键):[code]CREATE TABLE `quickstart`.`Person` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`firstName` VARCHAR(45) NOT NULL,
`lastName` VARCHAR(45) NOT NULL,
PRIMARY KEY(`id`)
)
ENGINE = InnoDB;[/code]

库文件及其版本:[code]antlr-2.7.6.jar
asm-attrs.jar
asm.jar
commons-collections-3.1.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
ejb3-persistence.jar
freemarker-2.3.13.jar
hibernate-annotations.jar
hibernate-cglib-repack-2.1_3.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate3.jar
javassist-3.4.GA.jar
jboss-archive-browsing.jar
jdbc2_0-stdext.jar
jta-1.1.jar
junit-3.8.1.jar
log4j-1.2.15.jar
mysql-connector-java-5.0.8-bin.jar
ognl-2.6.11.jar
slf4j-api-1.5.2.jar
slf4j-log4j12.jar
spring-test-2.5.6.jar
spring.jar
struts2-convention-plugin-2.1.6.jar
struts2-core-2.1.6.jar
struts2-dojo-plugin-2.1.6.jar
struts2-spring-plugin-2.1.6.jar
xml-apis.jar
xwork-2.1.2.jar[/code]

在Struts 2.1版本,想要使用dojo,需要加一行:[code]<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>[/code]

相应的,div和submit标签都有改变,比如submit标签这样改:[code]<sx:submit targets="personsDiv" notifyTopics="/save" />[/code]

但是,现在问题是,remove操作仍然不好用,下面的代码肯定要改一下:[code]<s:url id="removeUrl" action="remove">
<s:param name="id" value="id" />
</s:url>
<sx:a href="%{removeUrl}" targets="persons">Remove</sx:a>[/code]

把这个例子跑起来真是颇费周折,为了千千万同样在学struts 2.1的同学免受二遍苦免遭二茬罪,特意记下来。未完善部分请同学们自行研究。最后,如果你看到这个画面,恭喜你,applicatoin运行成功! 附件是我的app, 库文件与classes未上传。
[img]http://dl.iteye.com/upload/picture/pic/44087/d7edf5e8-e20a-39d6-9ecf-b49db1a94519.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值