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]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章