struts2從零開始(一)

2021-08-27 09:13:24 字數 1648 閱讀 4763

struts 2是struts的下一代產品,是在 struts 1和webwork的技術基礎上進行了合併的全新的struts 2框架。其全新的struts 2的體系結構與struts 1的體系結構差別巨大。struts 2以webwork為核心,採用***的機制來處理使用者的請求,這樣的設計也使得業務邏輯控制器能夠與servlet api完全脫離開,所以struts 2可以理解為webwork的更新產品。雖然從struts 1到struts 2有著太大的變化,但是相對於webwork,struts 2的變化很小。

所以在學習struts2的時候我們不能簡單的認為struts2是struts1的公升級版本,我們智慧型把它當作乙個全新的框架來學習,當然假如你以前學習過webwork那麼相信你學習struts2是很容易上手的。

下面就讓我們開始struts2的學習吧···(乙個簡單的登入)

步驟一:分包(搭好框架)

[img]

步驟二:匯入struts2開發所需要的jar包

步驟三:在src下新建乙個struts.xml檔案(開頭的dtd可以在 匯入的struts2-core-2.0.14.jar包中的struts-2.0.dtd中找到)

<?xml version="1.0" encoding="utf-8"?>

/sucess.jsp

步驟四:在 web.xml中配置過濾器(**如下)

struts2

org.apache.struts2.dispatcher.filterdispatcher

步驟五:編寫實體類(**如下)

package cn.zhuojingxinxi.entity;

public class person

public void setpname(string pname)

public int getpage()

public void setpage(int page)

}

步驟六:編寫action(由於struts2不同於struts1它沒有action與form,所有的東西都寫在乙個action中,為了**簡潔所以步驟五中編寫了乙個實體類,在這個action中struts2預設是將實體物件new出來的,而在struts1中必須手動new)

package cn.zhuojingxinxi.web;

import cn.zhuojingxinxi.entity.person;

public class loginaction

public void setperson(person person)

public string execute()

}

步驟七:編寫登入頁面(**如下)

編寫成功頁面(**如下)

$$

注:需要注意的是

1.由於使用的是實體物件,登入頁面相應的文字框的name必須是物件名.屬性。

2.在struts.xml中package節點必須加上extends="struts-default"。

PyTorch從零開始(一)

之前嘗試過tenano,caffe,keras,tensorflow,這幾個我個人最喜歡的還是tensorflow,因為是google出品,技術崇拜,文件很全,並且我看的deepmind的 都是用的tensorflow框架。之前看的目標檢測的 一般用caffe的很多,人臉識別方面也是caffe是主流...

SpringBoot從零開始(一)

上來先看的這篇部落格 idea新建乙個springboot mybatis mysql專案,以及遇到的問題分享。在其中第9步自動生成的過程中,出現了錯誤如下 the server time zone value is unrecognized or represents more than one ...

虛函式 從零開始 2

三,以一段 開始 include using namespacestd classa end 虛函式示例 2 intmain void a fun 定義乙個函式指標 a p newb fun a fun p fun fun a fun2 p fun deletep system pause 你能估算...