第一步,引入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. mongodb的安装和sql操作

    mongodb安装环境:centos6.5https://www.mongodb.org/dl/linux/x86_64wget https://fastdl.mongodb.org/linux/mo ...

  2. ionic2如何调用百度地图

    使用ionic2接入百度地图 在index.html中引入百度地图的js类库 <script type="text/javascript" src="http:// ...

  3. 寻找web根目录

    有时候,在利用一些命令执行漏洞时,可以以较高权限执行一些操作,但在我们想要上传shell的时候,却找不到网站根目录,下面是一些日常使用的寻找网站根目录的方法,记录下: 1.jsp 查看当前路径,在这个 ...

  4. python百度贴吧爬虫

    # -*- coding: utf-8 -*- #coding=utf-8 import urllib import urllib2 import re import thread import ti ...

  5. dockerfile 镜像构建

    1.镜像的构建有手动与自动方式,这里我们介绍自动化的构建方式 ,dockerfile常用指令如下 2.构建指令build Usage: docker image build [OPTIONS] PAT ...

  6. nodeJS学习(9)--- nodeJS模块:exports vs module.exports

    模块简介: 通过Node.js的官方API可以看到Node.js本身提供了很多核心模块 http://nodejs.org/api/ 这些核心模块被编译成二进制文件,可以 require('模块名') ...

  7. 洛谷P2168 荷马史诗 [NOI2015]

    题目描述 追逐影子的人,自己就是影子 ——荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马史诗>.但是由<奥德赛&g ...

  8. 用IHTMLDocument2接口获取页面上想要的数据,代替正则表达式

    原文发布时间为:2010-07-01 -- 来源于本人的百度文章 [由搬家工具导入] 1. 用 IHTMLDocument2::all 获得所有元素; 2. 用 IHTMLElementCollect ...

  9. boost 库的下载和编译_Visual Studio 2013(转)

    原文转自 http://blog.csdn.net/lp310018931/article/details/47791143 原文转自 http://m.blog.csdn.net/article/d ...

  10. C语言中的内存相关问题

    内存是用来存储数据与程序的,对我们写程序来说非常重要.所以内存对程序来说几乎是本质需求.越简单的程序需要越少的内存,而越庞大越复杂的程序需要更多的内存. 注意:在嵌入式系统中有ROM和RAM两类内存, ...