階段大綱 struts2 火推 01 02筆記

day01

 

階段大綱

  • ssh階段 6java

    • struts2
    • hibernate
    • ssh
  • NoSQL 2mysql

    • redis
    • mongoDB
    • linux------1-2
  • 企業項目 nlinux

    • CRM客戶管理系統
    • P2P金融借貸平臺
    • 企業級的解決方案
    • 簡歷指導-模擬面試 1-2

MAVEN

用於項目的構建、發佈、測試、打包的項目管理工具
  • 命令web

    • mvn test
    • mvn install
    • mvn clearn
    • mvn bulid
  • 圖形化界面面試

    • 應用與開發工具中做爲集成插件redis

      eclipse、myeclipse、IDE(全家桶)spring

maven結構和web項目的結構sql

maven結構:apache

jar:通常用於補丁管理的文件狀況下
pom:通常用於分佈式項目搭建
        pro-service
        pro-entity(VO)
        pro-utils
        pro-controller
        pro-pom---pom.xml

war:通常用於搭建工程(第一次搭建),而且只會建立一次---應用服務器(支持自解壓)

web結構設計模式

Tocmat

開發環境

切忌:全部路徑,不容許出現中文路徑或者特殊字符

搭建環境工具:

myeclipse、mysql5+、sqlyog、jdk1.七、tomcat七、maven

搭建步驟:

1:刪除環境變量中的tomcat設置
2:解壓縮各個軟件
3:切換本地jdk爲1.7
4:安裝myeclipse
5:設置myeclipse中jdk的版本
6:將tomcat配置到myeclipse中
7:將repository壓縮包,解壓到其它目錄
8:將maven中央倉庫,配置到myeclipse中
9:安裝sqlyog,並測試mysql鏈接

搭建圖文說明:

jdk配置步驟:

tomcat配置步驟:

maven配置步驟:

    1:將repository壓縮包,解壓到其它目錄
    2:修改maven的配置文件setting.xml
        將<localRepository>D:/repo</localRepository>這標籤去掉註釋,改爲本身的解壓目錄
    3:配置到myeclipse中,步驟以下:

生成web.xml步驟: 

day02

開發工具快捷鍵

ctrl+N:新建
ctrl+1:提示錯誤信息
ctrl+D:刪除
ctrl+/:行註釋
ctrl+\:取消行註釋
ctrl+shift+/:代碼段註釋
ctrl+shift+\:取消代碼段註釋
ctrl+H:快速查找任何文件信息、字符信息
ctrl+shift+O:導包
ctrl+T:查找類(支持模糊查找)
ctrl+R:查找文件(支持模糊查找、支持資源文件查找)
ctrl+shift+I:debug模式下,查看當前執行代碼信息
ctrl+G:定位文件(不經常使用)

DUBUG模式開發

注意:從今天開始,包括後續進入企業中,全部開發環境下的項目啓動,都要用debug模式啓動。

F5:進入方法內
F6:執行下一步
F7:跳出方法外
F8:執行到下一個斷點

Struts2

概述

是從webwork發展而來,而且屬於MVC的設計模式,其本質是一個servlet,充當的是C控制器層,和struts在名稱上區別不大,可是在代碼規範和內核上有很大的區別,其編碼規範和內核流程遵循的是webwork2的流程習慣

屬於非嵌入式框架,而且屬於非單例模式

演變:

優點

1:內部封裝了大量的攔截器
2:支持多種表現層的組件
3:攜帶大量的類型轉換器-----
    日期-----2017-10-10(支持)   2018年10月10日  20181010

結構原理

springMVC結構圖:

struts2結構圖:

搭建步驟

Spring搭建步驟:

    1:導包--(core\aop\ioc\jdbc.....、webMVC)
    2:增長配置文件信息applicationcontext.xml
    3:配置啓動容器

Struts2搭建步驟

    1:導包(struts2-core)

        <dependency>
          <groupId>org.apache.struts</groupId>
          <artifactId>struts2-core</artifactId>
          <version>2.5.13</version>
        </dependency>

    2:增長配置文件信息(struts.xml)

        <?xml version="1.0" encoding="UTF-8" ?>
        <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
            "http://struts.apache.org/dtds/struts-2.5.dtd">

        <struts>

        </struts>

    3:配置啓動容器

        <!-- struts2配置filter控制器 -->
        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>*.action</url-pattern>
        </filter-mapping>

struts.xml不提示標籤問題

入門示例1 - Hello Struts2

請求流程:

/hello.action-->StrutsPrepareAndExecuteFilter控制器->HelloAction--->result(struts.xml)--->hello.jsp

開發步驟:

1:遍寫hello.jsp文件
2:添加struts.xml中配置信息
3:編寫HelloAction.java文件
4:將工程部署到應用服務器Tomcat中
5:啓動運行
6:瀏覽器訪問:http://localhost:8081/ssh_13/demo/hello.action

代碼:

HelloAction.java:

/**
 * 1:接收請求(url或者帶有參數url)
 * 2:處理請求的方法
 *          public String execute(){.......}
 *              其中execute對應的是struts.xml中action中的method值
 * 3:返回請求結果集XXXX
 * 
 *          struts.xml----<result name="XXXX" type="">/.....</result>
 * @author likang
 * @date   2018-1-8 上午11:22:56
 */
public class HelloAction {

     public String execute(){
         return "success";
     }

}

struts.xml配置文件信息:

<!-- name:表明的是package名稱,能夠自定義,通常是按照系統的業務模塊劃分package
    extends:表明的是繼承struts2的核心配置文件,struts-default並非struts2的核心配置文件名
            而是struts-default.xml中的package對應的name值
    namespace:表明的是命名空間,若是不寫namespace值,則默認是/
 -->
<package name="demo" extends="struts-default" namespace="/demo">
    <!--hello.action
            name:表明的是請求名,可是請求後綴無需填寫
            class:表明的是請求所處理的action類
            method:接收接口請求的處理方法名,暫時寫死:execute
      -->
    <action name="hello" class="com.xdl.action.HelloAction" method="execute">
        <!--execute返回的result值:
                name:表明的是execute返回的標誌
                type:表明的是根據標誌,處理結果響應的類型,默認的是dispatcher
          -->
        <result name="success" type="dispatcher">/WEB-INF/jsp/hello.jsp</result>
    </action>
</package>

hello.jsp:

<h1>Hello Struts2</h1>

命名空間、請求後綴、組件默認值

/demo/user/hello.action

請求名:hello 請求後綴:.action 命名空間:/demo/user

加載順序問題:

http://localhost:8081/ssh_13/demo/dd/ddd/dd/hello.action

1:匹配請求後綴
2:匹配請求名:hello
3:匹配namespace,是一級一級匹配

請求後綴修改:

1:將web.xml中的url修改成/*.以下:
    <url-pattern>/*</url-pattern>
2:在struts.xml中增長以下配置信息:

    <!-- 修改struts2的默認後綴請求方式,struts.action.extension屬性來源於struts2的屬性文件
    default.properties
    若是是多個請求後綴,則用逗號隔開 -->
    <constant name="struts.action.extension" value="do"/>

接收、傳出參數

1:struts2中使用的全局變量來接收和傳出參數
2:爲參數增長getter和setter方法
3:變量名和請求參數名,名稱必須保持一致
4:頁面取值方式:${參數名 }

入門示例2 - 列表展現

請求流程:

/demo/list.do-->filter控制器--->ListAction-->result(struts.xml)->list.jsp

開發步驟:

1:編寫list.jsp頁面---${}
        C標籤
        導包:jstl
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

2:編寫ListAction.java

代碼以下:

ListAction.java:

/**
 * 列表展現
 * @author likang
 * @date   2018-1-8 下午2:43:23
 */
public class ListAction {

    public List<Dept> listDept;

    public String execute(){
        listDept = new ArrayList<Dept>();
        for (int i = 0; i < 10; i++) {
            Dept dept = new Dept();
            dept.setId(Long.valueOf(i));
            dept.setDeptName("java13_"+i);
            dept.setDeptNote("BeiJing"+i);
            listDept.add(dept);
        }
        return "success";
    }

    public List<Dept> getListDept() {
        return listDept;
    }

    public void setListDept(List<Dept> listDept) {
        this.listDept = listDept;
    }
}

struts.xml:

<!-- 列表頁面的跳轉 -->
    <action name="list" class="com.xdl.action.ListAction" method="execute">
        <result name="success" type="dispatcher">/WEB-INF/jsp/list.jsp</result>
    </action>

list.jsp

1:引用c標籤
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
2:遍歷取值

    <h1>列表展現</h1>
    <table>
        <c:forEach items="${listDept }" var="dept">
            <tr>
                <td>${dept.id }</td>
                <td>${dept.deptName }</td>
                <td>${dept.deptNote }</td>      
            </tr>
        </c:forEach>
    </table>

Struts2+Spring整合

相關文章
相關標籤/搜索