第一步,引入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整合的更多相关文章

  1. Struts2+Spring+Hibernate框架整合总结详细教程

    一.SSH三大框架知识总结 Struts 2是Struts的下一代产品,是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架.其全新的Struts 2的体系结构与S ...

  2. struts2+spring+hibernate(SSH)框架的搭建和总结

    SSH框架:struts2+spring+hibernate,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. struts2+spring+hibernat ...

  3. Struts2 Spring Hibernate 框架整合 Annotation MavenProject

    项目结构目录 pom.xml       添加和管理jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  4. Spring(八)SSH整合简述

    一.Spring与Struts2的整合 1.1.整合步骤 1.2.配置web.xml 1.3.配置spring配置文件applicationContext.xml 1.4.配置struts配置文件 1 ...

  5. struts2 convention插件

    1.struts2自2.1以后推荐使用Convention Plugin支持struts零配置支持(引入jar:struts2-convention-plugin-2.x.x.jar)①convent ...

  6. Struts+Spring+Hibernate项目整合AJAX+JSON

    1.什么是AJAX AJAX是 "Asynchronous JavaScript and XML" 的简称,即异步的JavaScript和XML. 所谓异步,就是提交一个请求不必等 ...

  7. struts2 Convention插件好处及使用

    现在JAVA开发都流行SSH.而很大部分公司也使用了struts2进行开发..因为struts2提供了很多插件和标签方便使用..在之前开发过程中总发现使用了struts2会出现很多相应的配合文件.如果 ...

  8. Struts2 Convention插件的使用(4)使用@Action注解返回json数据

    package com.hyy.action; import java.util.HashMap; import java.util.Map; import org.apache.struts2.co ...

  9. Struts2 Convention插件的使用(1)

    刚刚查阅官方文档(convention-plugin.html)并学习了Struts2的Convention插件,文章这里只作为一个笔记,建议大家去看官方文档比较清晰和全面. 需要在项目添加这些包 c ...

随机推荐

  1. ubuntu下安装JDK(复制)

    ubuntu 安装jdk 的两种方式:(本来jdk应该安装到/usr/lib/jvm下,但我安装到了/usr/local/lib/jvm下了) 1:通过ppa(源) 方式安装. 2:通过官网下载安装包 ...

  2. Mybatis通过接口的方式实现增删改查

    导入jar包 [mybatis] [oracle] 生成数据库 1.添加Mybatis的配置文件mybatis-config.xml 在src目录下创建一个mybatis-config.xml文件,如 ...

  3. 一、vue的数据双向绑定的实现

    响应式系统 一.概述 Vue通过设定对象属性的 setter/getter 方法来监听数据的变化,通过getter进行依赖收集,而每个setter方法就是一个观察者,在数据变更的时候通知订阅者更新视图 ...

  4. linux下编译libmysqlclient, 安装mysql-server mysql-client

    cmake . -DCMAKE_INSTALL_PREFIX=/home/zhangyawei/server/depends make make install 安装 mysql-server mys ...

  5. 洛谷P3832 [NOI2017]蚯蚓排队 【链表 + 字符串hash】

    题目链接 洛谷P3832 题解 字符串哈希然后丢到hash表里边查询即可 因为\(k \le 50\),1.2操作就暴力维护一下 经复杂度分析会发现直接这样暴力维护是对的 一开始自然溢出WA了,还以为 ...

  6. 优化Angularjs的$watch方法

    Angularjs的$watch相信大家都知道,而且也经常使用,甚至,你还在为它的某些行为感到恼火.比如,一进入页面,它就会调用一次,我明明希望它在我初始化之后,值再次变动才调用.这种行为给我们带来许 ...

  7. 旅行商(sale)

    旅行商(sale) 题目描述 camp国有n座城市,由1,2,-,n编号.城市由n–1条双向道路相连.任意两个城市之间存在唯一的道路连通.有m个旅行商,第i个旅行商会从城市ai旅行到城市bi,贩卖ci ...

  8. Python之时间:calender模块(日历)

    import calendar 1.星期 (1)calendar.day_name 星期的全称 print calendar.day_name for i in calendar.day_name: ...

  9. redis windows安装

    下载:https://github.com/MicrosoftArchive/redis/releases 命令行启动:redis-server.exe redis.windows.conf 以服务启 ...

  10. JavaScript (JS) 面向对象编程 浅析 (含对象、函数原型链、闭包解析)

    1. 构造函数原型对象:prototype ① 构造函数独立创建对象,消耗性能 function Person(name) { this.name = name; this.sayHello = fu ...