struts2以webwork優秀的設計思想為核心,吸收了 struts框架的部分優點,提供了一個更加整潔的mvc設計模式實現的web 應用程序框架。 struts2引入了幾個新的框架特性:從邏輯中分離出橫切關注點的攔截器、減少或者消除配置文件、貫穿整個框架的強大表達式語言、支持可變更和可重用的基于mvc模式的標簽api, struts2充分利用了從其它mvc框架學到的經驗和教訓,使得 struts2框架更加清晰靈活。
今天寫一篇struts2框架的,在很久很久以前,struts2可謂是稱霸江湖,縱然現在有后起之秀,但struts2依然可以成為老牌的主流框架,充當servlet,而且現在很多的招聘需求依然要求你會用struts2,并且有的面試官會問你它和springmvc的區別,今天先把代碼展示出來,對應的理論知識在初探—續編里面在詳細表述。
目錄結構:
helloworld.java
1
2
3
4
5
6
7
8
9
10
|
package action; import com.opensymphony.xwork2.actionsupport; public class helloworld extends actionsupport{ @override public string execute() throws exception { // todo auto-generated method stub system.out.println( "執行action" ); return success; } } |
struts.xml 配置文件
1
2
3
4
5
6
7
8
9
10
11
|
<?xml version= "1.0" encoding= "utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd" > <struts> < package name= "default" extends = "struts-default" > <action name= "helloworld" class = "action.helloworld" > <result name= "success" >/index.jsp</result> </action> </ package > </struts> |
web.xml
1
2
3
4
5
6
7
8
9
10
11
|
<?xml version= "1.0" encoding= "utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd" > <struts> < package name= "default" extends = "struts-default" > <action name= "helloworld" class = "action.helloworld" > <result name= "success" >/index.jsp</result> </action> </ package > </struts> |
jsp 展示頁
以上就是本次關于struts2框架基礎知識點的全部內容,希望能夠給你提供到幫助。
原文鏈接:http://www.cnblogs.com/shandouji1121/p/7868931.html