初學struts 2 , 配置及簡單例子

struts2與struts1實在有很大的不同,可以說是完全不相干的兩個東西.

 

如果用eclipse開發struts2的程序,

 

1.下載struts2 的包,解壓,複製到 lib目錄下

!注意~~~如果全部都複製過來的話可能會在tomcat運行,編譯時出現錯誤,如果複製得不夠又可能會報錯.

最最基本的需要7個jar

 

struts2-core-2.1.6.jar

xwork-2.1.2.jar

freemarker-2.3.13.jar

ognl-2.6.11.jar

spring-test-2.5.6.jar    (這個不知是不是必要的)

commons-fileupload-1.2.1.jar

commons-io-1.3.2.jar

 

還有 commons-logging-1.1.jar ,  junit-3.8.1.jar

struts2一個有約50個jar可以根據自己的需要加上

 

2.寫web.xml文件 要寫filter和filter映射

 

3.自己建個struts.xml文件,位置在src目錄下,編譯後它會在classes目錄下的

 

4.建1 action     extends   com.opensymphony.xwork2.ActionSupport

重載 execute()方法

 

5.建一result  (jsp頁面)

jsp頁面中可用 <s:property value="message" /> 輸出action中的屬性字段

用s標籤要加入庫

<%@ taglib prefix="s" uri="/struts-tags" %>

 

6.在struts.xml中寫配置,配置action 和 result

 

HelloWorld例子

http://struts.apache.org/2.x/docs/hello-world.html

struts.xml 寫法

http://struts.apache.org/2.x/docs/strutsxml.html

 

web.xml寫法

http://struts.apache.org/2.x/docs/webxml.html

 

Guides

http://struts.apache.org/2.x/docs/guides.html

 

 

 

 

 

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