导入这个插件,该插件的作用是替换掉struts.xml 原则是没有配置,全是约定

基本步骤

  1.新建HomeAction,里面有个execute方法return success,请求home.action就这样就能执行这个

    约定:home就是以前配置中的action的name属性值,没有方法名就默认execute

        HomeAction→home.action
        StudentHomeAction→student-home.action

     包名,请求的action必须放在action,actions,strut,struts中
        com.kaishengit.action.HomeAction → /home.action
        com.kaishengit.action.product.HomeAction → /product/home.action
        com.kaishengit.action.product.type.HomeAction → /product/type/home.action

  2.添加jsp文件.文件名定义为home-success.jsp,就这样就能到达这个jsp 该文件必须在一个content文件夹内,但是可以修改这个    文件夹

        <constant name="struts.convention.result.path" value="/WEB-INF/views/"/>

        /home.action success →/WEB-INF/content/home-success.jsp
        /home.action input → /WEB-INF/content/home-input.jsp
        /product/home.action success → /WEB-INF/content/product/home-success.jsp

  3.对于请求方法和跳转方式要靠注解来实现

      在Homeaction中定义另一种方法
      @Action("main")加上注解,添加main-success.jsp请求locallhost/main.action

@Action("main")
public String main() {
return SUCCESS;
}

跳转
对于params,奇数代表键,偶数个代表值

@Action(value="login",results={
@Result(name="success",type="redirectAction",params={"namespace","/admin","actionName","main"}),
@Result(name="input",type="redirectAction",params={"namespace","/admin","actionName","home","error","1001"})
})
public String login() {
Admin currAdmin = adminService.login(admin);
if(currAdmin == null) {
return INPUT;
} else {
putSession("curr_Admin", currAdmin);
return SUCCESS;
}
}

4.对于主配置文件,struts.xml的常量设置,拦截器,global-result还是要自己配置

  但是对于过滤器什么的,convention是存在默认包的.所以要修改才行
  <constant name="struts.convention.default.parent.package" value="basePackage"/>

5.命名空间

com.kaishengit.action.product.HomeAction → /product/home.action
可以com.kaishengit.action.HomeAction→ /product/home.action
要在HomeAction上注解@namespace("product")
这时候请求到达的jsp都要在/content/product/xxxx

struts2 convention-plugin的更多相关文章

  1. Struts2 Convention Plugin ( struts2 零配置 )

    Struts2 Convention Plugin ( struts2 零配置 ) convention-plugin 可以用来实现 struts2 的零配置.零配置的意思并不是说没有配置,而是通过约 ...

  2. struts2使用Convention Plugin在weblogic上以war包部署时,找不到Action的解决办法

    环境: struts 2.3.16.3 + Convention Plugin 2.3.16.3 实现零配置 现象:以文件夹方式部署在weblogic(10.3.3)上时一切正常,换成war包部署,运 ...

  3. Struts2 - Conversion Plugin

    转载:http://www.cnblogs.com/ikuman/archive/2013/11/04/3403073.html 1.struts2自2.1以后推荐使用Convention Plugi ...

  4. struts2 convention插件

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

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

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

  6. Struts2 Convention插件的使用(3)方法前的@Action注解

    package com.hyy.action; import org.apache.struts2.convention.annotation.Action; import com.opensymph ...

  7. ssi整合报错org.apache.struts2.convention.ConventionsServiceImpl.determineResultPath(ConventionsServiceImpl.java:100)

    java.lang.RuntimeException: Invalid action class configuration that references an unknown class name ...

  8. struts2 Convention插件零配置,使用注解开发

    从struts21开始,struts2不再推荐使用codebehind作为零配置插件,而是改用Convention插件来支持零配置.与以前相比较,Convention插件更彻底. 使用Conventi ...

  9. Struts2 convention插件试用+ Spring+Hibernate SSH整合

    第一步,引入struts2-convention-plugin-2.2.1.jar 然后,改动配置文件. 我是在struts.properties文件里改动的: struts.objectFactor ...

  10. Struts2 Convention插件的使用

    转自:http://chenjumin.iteye.com/blog/668389 1.常量说明 struts.convention.result.path="/WEB-INF/conten ...

随机推荐

  1. 收藏:左路Deep Learning+右路Knowledge Graph,谷歌引爆大数据

    发表于2013-01-18 11:35| 8827次阅读| 来源sina微博 条评论| 作者邓侃 数据分析智能算法机器学习大数据Google 摘要:文章来自邓侃的博客.数据革命迫在眉睫. 各大公司重兵 ...

  2. 有关UIWebView的SSL总结

    在网上找了非常多文章差点儿相同都是一样的,基本上都是关于NSURLConnection的文章. 如今把几个比較好的连接分享给大家http://blog.csdn.net/pingchangtan367 ...

  3. loadRunner 11.0 安装及破解

    http://jingyan.baidu.com/article/20095761b31b58cb0621b463.html 破解时必须是管理员账户登录.

  4. SQL Server索引进阶:第九级,读懂执行计划

    原文地址: Stairway to SQL Server Indexes: Level 9,Reading Query Plans 本文是SQL Server索引进阶系列(Stairway to SQ ...

  5. JavaScript 深入学习及常用工具方法整理 ---- 01.浮点数

    在JavaScript中是不区分整数值和浮点数值的,其中所有的数字均用浮点数值表示.JavaScript采用IEEE 754标准(有兴趣可以浏览网络规范分类下的IEEE 754标准,需要原文件请在留言 ...

  6. Java中Iterator(迭代器)的用法及其背后机制的探究

    在Java中遍历List时会用到Java提供的Iterator,Iterator十分好用,原因是: 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结 ...

  7. 2015 5.16 C# 继承和多态

    类的层次结构有两种基本的构造方式  自顶向下  自底向上 基类的保护成员是指允许派生类的方法代码访问,而不是指通过派生类的对象访问 如果基类中的字段通过公有且可读写的属性进行了封装,那么建议将字段定义 ...

  8. (Problem 53)Combinatoric selections

    There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...

  9. 第一个VC++ win32程序 绘制简单图形

    创建一个VC++ win32 打开VS 新工程类型中选择Win32----Win32 Project  自己取个名字(假如叫做My1stWin) 一路next 系统会自动生成好最基本的代码  然后我们 ...

  10. 【转】C++ stringstream介绍,使用方法与例子

    原文来自:http://www.cnblogs.com/lancidie/archive/2010/12/03/1895161.html C++引入了ostringstream.istringstre ...