- 浏览: 157384 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
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-annotations-example-1.html
注意:
1 必须引入struts2-convention-plugin-2.1.6包
2 WelcomeUserAction 类要放在 action命名的包下 并要用*Action 来命名类
3 successPage.jsp要放在web-inf/results目录下 这个是在struts.properties 根据struts.convention.result.path=/results来配置的
一搭建环境
jdk1.6 struts2.1.6 tomcat6.0
所需包
01.commons-fileupload-1.2.1
02.commons-io-1.3.2
03.commons-logging-1.1
04.freemarker-2.3.13
05.junit-3.8.1
06.ognl-2.6.11
07.spring-test-2.5.6
08.struts2-convention-plugin-2.1.6
09.struts2-core-2.1.6
10.xwork-2.1.2
二代码
web.xml
WelcomeUserAction.java
index.jsp在web-info下
successPage.jsp 在web-inf/results
struts.properties
四运行
http://localhost:8080/Struts2_Annotations2/
注意:
1 必须引入struts2-convention-plugin-2.1.6包
2 WelcomeUserAction 类要放在 action命名的包下 并要用*Action 来命名类
3 successPage.jsp要放在web-inf/results目录下 这个是在struts.properties 根据struts.convention.result.path=/results来配置的
一搭建环境
jdk1.6 struts2.1.6 tomcat6.0
所需包
01.commons-fileupload-1.2.1
02.commons-io-1.3.2
03.commons-logging-1.1
04.freemarker-2.3.13
05.junit-3.8.1
06.ognl-2.6.11
07.spring-test-2.5.6
08.struts2-convention-plugin-2.1.6
09.struts2-core-2.1.6
10.xwork-2.1.2
二代码
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_Annotations2</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>
WelcomeUserAction.java
package com.test.action; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; public class WelcomeUserAction { private String userName; private String message; @Action(value = "/welcome", results = { @Result(name = "success", location = "/results/successPage.jsp") }) public String execute() { message = "Welcome " + userName + " !"; return "success"; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
index.jsp在web-info下
<%@ 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>Annotations1</title> </head> <body> <body> <s:form action="welcome"> <s:textfield name="userName" label="User Name" /> <s:submit /> </s:form> </body> </html>
successPage.jsp 在web-inf/results
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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>Welcome User</title> </head> <body> <h1>${message}</h1> </body> </html>
struts.properties
struts.convention.result.path=/results
四运行
http://localhost:8080/Struts2_Annotations2/
评论
5 楼
acang84n
2012-04-11
难得是2.3的版本注解方式不一样!?
4 楼
acang84n
2012-04-11
为什么用struts2-convention-plugin-2.3.1.2 ,
就会不能用 @Action(value = "/welcome", results = { @Result(name = "success", location = "/results/successPage.jsp") })
对方法进行注解呢?
就会不能用 @Action(value = "/welcome", results = { @Result(name = "success", location = "/results/successPage.jsp") })
对方法进行注解呢?
3 楼
iamaj2eeprogrammer
2011-11-25
非常感谢你给出的例子!
2 楼
hdwmp123
2011-08-11
谢谢~~~
1 楼
lineshow
2011-05-11
非常感谢你给出的例子!
发表评论
-
java 图片压缩
2013-10-17 14:30 522http://fandayrockworld.iteye.co ... -
java的spring的quartz 时间配置相应字符串的说明与实例
2011-12-15 11:19 971本文源自:http://js.sse6.cn/gzsgfrz/ ... -
Spring事务配置的五种方式
2011-01-19 09:12 754http://www.blogjava.net/robbie/ ... -
log4j.xml配置 分级打印日志和打印到指定文件中
2009-11-26 12:50 4235<?xml version="1.0&qu ... -
Spring启动时出现 ERR=12505 异常
2009-11-26 12:47 1517这是由于,spring配置文件中有数据源配置错误,修改后就可以 ... -
用正则表达式替换手机号码前缀86
2009-11-25 09:24 3853Pattern p2 = Patt ... -
ibatis sqlMapConfig settings 中属性用法
2009-09-28 14:12 5088转自 http://zhangzuanqian.iteye.c ... -
SqlMapException: There is no statement named解决方法
2009-09-28 12:51 5329报如下异常解决方法 sqlMapConfig 里加入 < ... -
关于struts2无法加载struts.properties的问题
2009-09-25 17:52 1320http://blog.chinaunix.net/u/200 ... -
Spring2.5、Struts2、Ibatis2.3开发框架搭建
2009-09-25 17:47 1848Spring2.5、Struts2、Ibatis ... -
Struts2 注解配置 demo1
2009-08-21 16:25 1741from http://www.vaannila.com/st ... -
Struts2 UI Tags Example
2009-08-21 11:39 1467转自处:http://www.vaannila.com/str ... -
Struts2 HelloWorld MAX的struts教程的demo
2009-08-20 15:51 1103原文http://www.blogjava.net/max/c ... -
使用Struts2
2009-08-20 14:45 1068原文http://developer.51cto.co ... -
JSP乱码解决 之 pageEncoding和contentType属性,UTF-8 GBK gb2312 详解
2009-07-30 10:14 1461文章来源于志伟教程资 ... -
Tomcat的JNDI配置
2009-07-06 15:53 1461驱动需要拷到tomcat/common/lib/目录 1 we ... -
web应用 xml方式配置
2009-07-06 15:49 743编写一个xml文件,然后放到tomcat目录/conf/Cat ... -
Tomcat类装载器
2009-07-06 15:12 797context.xml: <Context> ... -
解决request.getParameter()中文乱码的问题
2009-02-21 16:52 4946jsp页面中 用click事件调用js 此时的页面编码要用UT ... -
搭建SVN服务端
2009-02-09 11:12 1244转载http://hi.baidu.com/axhack/bl ...
相关推荐
struts2将请求在Action中封装为Map并将配置文件放到web-info中还可以自定义配置文件位置就是不将struts.xml放到src下但还是不如spring mvc 的封装来得方便
struts2范例,含登录跳转,文件上传及不跳转上传,注解和配置2种方式,适合初学者和复习用,采用struts2.1
2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。 4.在服务端分页查询功能,优点:实时性:跳页才查询。数据量小:只加载当前页的记录...
整合使用最新版本的三大框架(即Struts2...参考文档:(感谢下边的两位原创作者,另外我在结合两个优点的基础之上,把所有的配置换成了注解的配置方案。) http://blog.csdn.net/songanling/article/details/22454973 ...
自己学Struts的注解,写的一个零配置小demo。 很简单很简单,只供新手学习。
dwr配置文件和注解两种方式的两个...一个sprig3+dwr3+jpa+struts2,基于注解的完整demo 一个sprig2+dwr2+hibernate3+struts1,基于配置文件的完整demo http://blog.csdn.net/zuxianghuang/article/details/7376247
基于注解Annotation的最新版SSH(Struts2.3.7+Hibernate4.1.9+Spring3.2.0)整合开发,真正实现零配置。记得修改数据源。
无聊之秋,做了个电子商务网站demo,巩固了一下对SSH三大开源框架的认识,比且融入了Annotation减少了xml配置文件的出现,本人只是个菜鸟,希望该资源能对一些朋友略有帮助!
一、部分软件/库版本 Maven:3.0.5 struts2.2.3-spring3.0.6-hibernate3.6.6 ...2.全注解,实现零配置 3.对Service/Dao层做了封装: 实现了对任何通用CRUD(增删改查)操作,不用写任何Service/Dao层代码
首先我说下我做的这个插件:用于springMVC,由于springMVC没有像struts1 2 那样,有个专门的跳转路径的配置文件,导致springMVC不能直观方便的看到方法(Action)和路径对应的匹配,所以我这个插件会把eclipse里工作...