Struts2 convention插件试用+ Spring+Hibernate SSH整合
第一步,引入struts2-convention-plugin-2.2.1.jar
然后,改动配置文件。
我是在struts.properties文件里改动的:
struts.objectFactory = spring
struts.devMode = true
struts.i18n.encoding = UTF-8
struts.convention.result.path =/WEB-INF/jsp/
struts.convention.package.locators = action,actions,struts,struts2,control,controls,test
struts.convention.action.suffix =Action,Control
第一行。与spring整合。
第二行,启用struts开发模式。方便调试。
第三行,i18n
第四行,指定默认视图的路径,全部视图资源将从此路径下搜索。
第五行。指定搜索的包名。因为个人喜欢将控制类的包命名为*.control,所以增加control包。又增加了test包
第六行。指定class文件的文件结尾名。比方,默认仅仅搜索AbcAction这种类。如今也可搜索AbcControl这种类。
Java測试代码(部分)项目地址:http://localhost:8080/Photo/
package com.lgh.test; import java.util.List; import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results; import com.lgh.common.tools.json.JsonUtil;
import com.lgh.sys.entity.User;
import com.opensymphony.xwork2.Action; @Scope("prototype")
@Controller
@Namespace("/name")//指定命名空间
public class TestControl implements Action { @Autowired
private TestService testService; private User user;
private String name; private List<User> List; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
}
// http://localhost:8080/Photo/name/test 能够訪问到此action
@org.apache.struts2.convention.annotation.Action(value = "test", results = {
@Result(name = "success", location = "/index.jsp", type = "redirect"),
@Result(name = "register", location = "/haha.jsp", type = "redirect") })
public String test() throws Exception {
List = testService.findBySome("1", User.class);
user = testService.findBySome("1", User.class).get(0);
name = user.getName();
JsonUtil.outToJson(ServletActionContext.getResponse(), user);
return SUCCESS;
} // http://localhost:8080/Photo/haha/register 能够訪问到此action 注意此处value以斜杠"/"开头 表示绝对路径了。namespace失效
@org.apache.struts2.convention.annotation.Action(value = "/haha/register", results = {
@Result(name = "success", location = "/index.jsp", type = "redirect"),
@Result(name = "register", location = "./haha.jsp", type = "redirect") }) //运行后会跳转到 http://localhost:8080/Photo/haha/haha.jsp ./haha.jsp和直接写haha.jsp效果一样,可是写/haha.jsp之后,会跳转到 http://localhost:8080/Photo/haha.jsp 相似于绝对路径
public String register() throws Exception {
List = testService.findBySome("1", User.class);
user = testService.findBySome("1", User.class).get(0);
name = user.getName();
// JsonUtil.outToJson(ServletActionContext.getResponse(), user);
return "register";
} @Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return null;
} }
SSH整合后的框架下载,请用MyEclipse导入。
MySQL的driver和jackson1.9.11-all的jar包没有上传。请自行搜索下载。
http://download.csdn.net/detail/lgh06/8039749 免积分 全然免费哦。
写的比較烂,见谅……
Struts2 convention插件试用+ Spring+Hibernate SSH整合的更多相关文章
- Struts2+Spring+Hibernate框架整合总结详细教程
一.SSH三大框架知识总结 Struts 2是Struts的下一代产品,是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架.其全新的Struts 2的体系结构与S ...
- struts2+spring+hibernate(SSH)框架的搭建和总结
SSH框架:struts2+spring+hibernate,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. struts2+spring+hibernat ...
- Struts2 Spring Hibernate 框架整合 Annotation MavenProject
项目结构目录 pom.xml 添加和管理jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...
- Spring(八)SSH整合简述
一.Spring与Struts2的整合 1.1.整合步骤 1.2.配置web.xml 1.3.配置spring配置文件applicationContext.xml 1.4.配置struts配置文件 1 ...
- struts2 convention插件
1.struts2自2.1以后推荐使用Convention Plugin支持struts零配置支持(引入jar:struts2-convention-plugin-2.x.x.jar)①convent ...
- Struts+Spring+Hibernate项目整合AJAX+JSON
1.什么是AJAX AJAX是 "Asynchronous JavaScript and XML" 的简称,即异步的JavaScript和XML. 所谓异步,就是提交一个请求不必等 ...
- struts2 Convention插件好处及使用
现在JAVA开发都流行SSH.而很大部分公司也使用了struts2进行开发..因为struts2提供了很多插件和标签方便使用..在之前开发过程中总发现使用了struts2会出现很多相应的配合文件.如果 ...
- Struts2 Convention插件的使用(4)使用@Action注解返回json数据
package com.hyy.action; import java.util.HashMap; import java.util.Map; import org.apache.struts2.co ...
- Struts2 Convention插件的使用(1)
刚刚查阅官方文档(convention-plugin.html)并学习了Struts2的Convention插件,文章这里只作为一个笔记,建议大家去看官方文档比较清晰和全面. 需要在项目添加这些包 c ...
随机推荐
- PAT1029
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及实际被输入的文字,请你列出肯定坏掉的那些键. 输入格式: 输入在2行中分别给出应该输入的文字.以及实际 ...
- 一些echarts的基本图形
先拿一个图形渲染过程举例 引用处 <bar ref="ARPUChart" v-if="ARPUChart" style="width:500p ...
- BZOJ 1855: [Scoi2010]股票交易(DP+单调队列)
1855: [Scoi2010]股票交易 Description 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未 ...
- android在JNI_OnLoad入口函数下断点动态调试so库
一般来说,很多APK的校验代码,都会在程序运行的时候自动加载一些动态so库,然后执行这些库中的校验代码.所以为了能够通过程序的校验,我们必须在执行这些函数之前下断点——理想的方法就是在JNI_OnLo ...
- The OAuth 2.0 Authorization Framework
The OAuth 2.0 Authorization Framework Abstract The OAuth 2.0 authorization framework enables a thi ...
- Ajax 控件 的使用 以及js调用后台方法【自己总结一下】
原文发布时间为:2009-05-16 -- 来源于本人的百度文章 [由搬家工具导入] 源码:http://download.csdn.net/source/1340120 (js调用后台方法只在源 ...
- case when then else 详解
原文发布时间为:2008-10-15 -- 来源于本人的百度文章 [由搬家工具导入] sql语句判断方法之一 Case具有两种格式。简单Case函数和Case搜索函数。 --简单Case函数 CASE ...
- C++ 求幂的运算符是什么?
1.VB里面求幂的运算符是“^” 2.C++没有求幂的运算符, c++头文件加 #include<math.h>使用pow(x,y),可算出x的y次幂 3.C++中 “^”是按位“异或”运 ...
- CC2540介绍
1. 介绍 CC2540是一款2.4GHz Bluetooth® low energy SOC,基于8051 MCU 首先,你需要硬件设备 笔者的开发板为CC2540DK 得到开发板的同时应该还有TI ...
- C++学习(二):学会使用stringstream
1.前言 今天在CppTemplateTutorial群里,有人问了一个问题:这一堆add怎么简化掉 https://wandbox.org/permlink/vDPDwMFbBIQSSymS.代码如 ...