1. 程式人生 > >struts2(基礎1)

struts2(基礎1)

一.概念
1.1 struts2的作用:
struts2的作用
1.2 struts2的優點:

  1. 自動封裝引數
  2. 引數校驗
  3. 結果的處理(轉發|重定向)
  4. 國際化
  5. 顯示等待頁面
  6. 表單的防止重複提交

    struts2具有先進的架構以及思想,它與struts1並沒有實質上的關係,它的前身是webwork框架。

二.搭建
第一步,導包:
在下載的struts2-版本號檔案中,點選apps,解壓其中struts2-blank.war,其中lib資料夾包含struts2框架必要的jar包,而其他jar包可選。
第二步,書寫Action類:

public class HelloAction{
    public String hello(){
        System.out.print("hello");
        return "success";   
    }
}

第三步,書寫src下的struts.xml檔案:
這裡寫圖片描述
注:!DOCTYPE 約束,必須的。
第四步,將struts2核心過濾器配置到web.xml:
這裡寫圖片描述
第五步,測試
localhost:8080/專案名/hello/HelloAction
三.訪問流程&構架
這裡寫圖片描述
四.配置詳解
4.1struts.xml配置
這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述
4.2常量配置
4.2.1預設常量配置位置
這裡寫圖片描述
4.2.2修改strut2常量配置的方式(最常用方式)
在src/struts.xml中配置
4.2.3常用配置
這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述
4.3配置進階
4.3.1動態方法呼叫
這裡寫圖片描述

這裡寫圖片描述
4.4Action類的書寫方式(常用方法)
這裡寫圖片描述