struts2以webwork優(yōu)秀的設(shè)計(jì)思想為核心,吸收了 struts框架的部分優(yōu)點(diǎn),提供了一個(gè)更加整潔的mvc設(shè)計(jì)模式實(shí)現(xiàn)的web 應(yīng)用程序框架。 struts2引入了幾個(gè)新的框架特性:從邏輯中分離出橫切關(guān)注點(diǎn)的攔截器、減少或者消除配置文件、貫穿整個(gè)框架的強(qiáng)大表達(dá)式語(yǔ)言、支持可變更和可重用的基于mvc模式的標(biāo)簽api, struts2充分利用了從其它mvc框架學(xué)到的經(jīng)驗(yàn)和教訓(xùn),使得 struts2框架更加清晰靈活。
今天寫一篇struts2框架的,在很久很久以前,struts2可謂是稱霸江湖,縱然現(xiàn)在有后起之秀,但struts2依然可以成為老牌的主流框架,充當(dāng)servlet,而且現(xiàn)在很多的招聘需求依然要求你會(huì)用struts2,并且有的面試官會(huì)問(wèn)你它和springmvc的區(qū)別,今天先把代碼展示出來(lái),對(duì)應(yīng)的理論知識(shí)在初探—續(xù)編里面在詳細(xì)表述。
目錄結(jié)構(gòu):
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( "執(zhí)行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 展示頁(yè)
以上就是本次關(guān)于struts2框架基礎(chǔ)知識(shí)點(diǎn)的全部?jī)?nèi)容,希望能夠給你提供到幫助。
原文鏈接:http://www.cnblogs.com/shandouji1121/p/7868931.html