1002_____struts_____零配置

文章只是做一个记录,以便日后查阅
本人技术有限,有误的地方请友善指出,谢谢,O(∩_∩)O~


每次都要在struts.xml中配置action ,是不是觉得很麻烦呢?
可不可以不用配置,直接访问呢?
下面就来介绍struts的零配置 【事实上,只是预定大于配置而已】

1,在struts.xml中配置常量
<!-- struts 零配置 常量配置 -->
<constant name="struts.convention.result.path" value="/pages"></constant><!-- 配置页面返回路径 -->
<constant name="struts.convention.package.locators" value="action"></constant><!-- 哪些包下面的文件会被当做Action类来检索 -->
<constant name="struts.convention.action.name.separator" value="_" /><!-- 这里就是配置的如何分Action的name 用’-’ 注意是去掉最后的Action的 -->

2,导入包
struts2-convention-plugin-2.3.1.2.jar

3,指定action的访问名称
package action;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ActionSupport;

@Action("/testStruts")
public class TestStrutsAction extends ActionSupport {
private static final long serialVersionUID = -5561563641398878951L;

public String method1(){
System.out.println("run execute method.....");
return "execute_success";//根据配置 这里的返回页面是 pages/testStruts_execute_success.jsp 【这里我就不创建了】
}
}

4,启动tomcat 报错
java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils

导入:commons-lang-2.4.jar


5,启动tomcat 报错
java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor

导入:asm-3.3.jar

6,启动tomcat 报错
java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor

导入:asm-commons-3.3.jar

7,
启动tomcat正常
输入地址:http://192.168.9.33:8080/ibook/testStruts!method1.action
访问成功


结构:
[img]http://dl.iteye.com/upload/picture/pic/129063/925d1315-a3e2-3bc9-96e3-d9e0a9b293e0.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值