Struts2注解终于掌握一点儿皮毛了,现在在此处记录下来,供自己日后回顾&参考!
实现步骤:
1,在web.xml文件中加入要扫描的包,加入的位置是Struts2在web.xml文件中配置的filter标签中的位置,需要配置一个<init-param>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.harry.struts.action</param-value>
</init-param>
2,在struts.xml配置文件中,配置一个<package>,在这个package中并没有<action>配置
<package name="struts_conversion" extends="struts-default"
namespace="/conversion">
</package>
3,开始编写简单的Action类,只为测试注解的正确使用!
(Attention:我的result指向的location是在webroot根目录下的,请注意!)
另外:在struts2刚开始的版本中,@Result中的location原来是value,但是现在为location
package com.harry.struts2.action;
import java.util.Date;
import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
@Namespace("/conversion")
@Action("annoAction")
@Results
({ @Result(name = "input", location = "/index.jsp"),
@Result(name = "success", location = "/success.jsp") })
public class AnnoAction
{
public String testAnno()
{
return "success";
}
}
4,简单的JSP页面代码:
index.jsp请求页面:
<html>
<body>
<s:form action="annoAction!testAnno" namespace="/conversion">
<s:submit value='Submit'/>
</s:form>
</body>
</html>
success.jsp页面:
<html>
<body>
<font size='+4'>Test annotation success ! </font>
</body>
</html>
分享到:
相关推荐
完全使用Annotation,及XML,各立独立与配合混合使用,有加注释,我也是初学者,适合新手,老鸟免了
spring_3.2.0+hibernate_4.1.9+struts2_2.3.7全annotation编写,采用MD5加密,已实现登录,注册,注销,验证码,带sql文件,src下面的SystemGlobals.properties文件配置下数据库就可以直接运行
struts2+spring+hibernate(注解)实现的登陆
struts2 使用Annotation配置实现的小例子,转载供大家学习使用,里面包括了所需的jar包
struts2-Annotation
该程序实现了零配置通过注解代替了hibernate中繁琐的hb.XML配置 使用spring 控制翻转 ,托管hibernate和struts2
多框架搭建系统平台(采用annotation方式): Flex+Blazeds+Spring+Hibernate(Flex调用java查询后台数据) JSP+Struts+spring+Hibernate(完成用户登录) 共同搭建系统
博文链接:https://flym.iteye.com/blog/174358
struts2 annotation 注解的详细介绍及使用方法
参考博文:http://blog.csdn.net/u011638419/article/details/41743049
本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
马士兵视频里的struts2 hibernate3 spring2.5 annotation 整合 绝对好用 里面还有jar包 部署就可以用
NULL 博文链接:https://vincenta.iteye.com/blog/1535330
struts2,json-plugin, 并全注解零配置
Struts2的“零配置”特性是Struts2的新功能,可能会出现一些小Bug,所以企业开发者请慎重使用该特性, ...如果用的是Annotation的Struts2,就要将struts.xml去掉,否则即使将struts.xml中的内容注销,也会报错;
通过产生临时文件下载之后,再通过线程删除临时文件
Struts2 Spring Hibernate 框架整合 Annotation Maven project