第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

Struts2入門

  • 這個方法我只是針對通配符使用的

    https://img1.sycdn.imooc.com//5b696d460001caf606140358.jpg

    我看到視頻里面兩個方法好像都是return SUCCESS;所以改了url地址一直都無法跳轉(zhuǎn)到其他兩個頁面,如果有和我一樣的情況的同學(xué)可以把success改為"add"和"update",這樣就沒問題了

    查看全部
  • Struts官方網(wǎng)站:http://struts.apache.org/

    歷史版本:http://archive.apache.org/dist/struts/

    查看全部
  • 搭建Struts環(huán)境步驟:

    查看全部
  • Struts2環(huán)境:

    查看全部
  • Struts2

    查看全部
  • 數(shù)據(jù)類型轉(zhuǎn)換錯誤時(shí)會返回INPUT

    (1)校驗(yàn)方法在LoginAction中添加validate()

    public?void?validate(){
    ????if(user.getUsername()==null||"",equals(user.getUsername)){
    ????????this.addFieldError("username","用戶名不可為空!");
    ????}
    }

    (2)表單頁面加入struts2標(biāo)簽

    <%@?taglib?prefix="s"?uri="/struts-tags"?%>
    <input?type="text"?name="username"?/><s:fielderror?name="username"></s:fielderror>


    查看全部
  • action接收參數(shù)

    有表單如下:

    <form?action="LoginAction"?method>
    ????<input?type="text"?name="username"?/>
    ????<input?type="password"?name="password"?/>
    ????<input?type="submit"?value="提交"?/>
    </form>

    創(chuàng)建LoginAction,添加login()

    public?String?login(){
    
    ????//********
    ????return?SUCCESS;
    }

    1、屬性接收

    //在LoginAction中建立username、password屬性
    private?String?username;
    private?String?password;
    //實(shí)現(xiàn)其get、set方法
    //login()可以調(diào)用username、password

    注:屬性接收簡單,但對于屬性多的情況不利于代碼維護(hù)

    2、DomainModel接收

    ????(1)創(chuàng)建user類

    public?class?User{
    ????private?String?username;
    ????private?String?password;
    ????//實(shí)現(xiàn)其get、set方法
    }

    ????(2)LoginAction中聲明User

    private?User?user;
    //實(shí)現(xiàn)User的get、set方法

    注:在form表單中,input的name要指定類名如user.username.

    3、實(shí)現(xiàn)ModelDriven接口

    LoginAction實(shí)現(xiàn)ModelDriven接口

    public?class??LoginAction?extends?ActionSupport?implements?ModelDriven<User>{
    ????//用ModelDriven必須實(shí)例化User
    ????private?User?user=new?User();
    ????public?String?login(){
    ????????return?SUCCESS;
    ????}
    ????public?User?getModel(){
    ????????return?user;
    ????}

    4、復(fù)雜參數(shù)接收

    (1)user類包含ListBook類

    public?class?User{
    ????private?String?username;
    ????private?String?password;
    ????private?List<ListBook>?listbook;
    ????//實(shí)現(xiàn)其get、set方法
    }

    (2)新建ListBook類

    public?class?ListBook{
    ????private?String?bookname;
    ????private?int?price;
    ????//實(shí)現(xiàn)其get、set方法
    }

    (3)form表單中添加

    <input?type="text"?name="listbook[0].bookname">
    <input?type="text"?name="listbook[0].price">
    <input?type="text"?name="listbook[1].bookname">
    <input?type="text"?name="listbook[1].price">

    (4)login()中獲取

    String?book1=user.getListBook().gte(0).getBookName();
    String?book2=user.getListBook().gte(1).getBookName();


    查看全部
  • 1、多個配置文件可以用<include>,在struts.xml中統(tǒng)一配置

    <include?file="xx.xml"></include>

    2、設(shè)置常量(此方法可以頂替struts.properties文件)

    <constant?name="常量名"?value="常量值"></constant>

    3、動態(tài)方法調(diào)用+通配符使用

    <action?name="*_*"?method="{2}"?class="包全名.{1}">
    ????<!--?*_*中*代表任意字符,_代表固定格式
    ????????{1}{2}是第幾個*所代表的字符串
    ????????例:hello_add
    ????????{1}=hello【action名】;{2}=add【action中方法名】
    ????????調(diào)用hello.acton中的add()
    ????-->
    ????<result>/xx.jsp</result>
    </action>

    4、默認(rèn)action(用來處理找不到相應(yīng)action時(shí),統(tǒng)一跳到一個友好界面)

    <default-action-ref?name="aaa"></default-action-ref>
    <action?name="aaa">
    ????<result>/xx.jsp</result>
    </action>
    1. 注:當(dāng)同包中存在action name="*_*"時(shí),訪問路徑寫成hello_aaa不能跳到指定的目標(biāo)。用為會默認(rèn)先匹配action部分,匹配成功后就不再找默認(rèn)action了。

    5、struts2后綴

    <!--?struts.xml中添加常量修改action后綴?-->
    <constant?name="struts.action.extension"?value="html"></constant>
    <!--?1、后綴再寫action報(bào)錯,要改成.html?
    ?????2、該常量也可以在struts.properties中配置
    ?????????struts.action.extension=action,do,struts2
    ?????3、也可以在過濾器<filter>中配置
    ?????????<init-param>
    ?????????????<param-name>struts.action.extension</param-name>
    ?????????????<param-value>do</param-value>
    ?????????</init-param>
    -->


    查看全部
  • Struts2是基于MVC設(shè)計(jì)模式的Web應(yīng)用程序框架,能節(jié)省Web應(yīng)用開發(fā)時(shí)間

    Struts實(shí)例程序創(chuàng)建步驟(工具M(jìn)yeclipse10+tomcat7+jdk1.7):

    1、創(chuàng)建Web Project

    2、導(dǎo)入jar包,在src下建立struts.xml

    3、打開web.xml,添加

    <filter>
    ????<filter-name>[過濾器名]</filter-name>
    ????<filter-class>???
    ????org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    ????</filter-class>
    </filter>
    <filter-mapping>
    ????<filter-name>[過濾器名]</filter-name>
    ????<url-pattern>/*</url-pattern>
    ????<!--?/*代表過濾所有路徑?-->
    </filter-mapping>

    4、打開struts.xml,假如文檔類型定義DTD(用myeclipse直接添加struts后不用會搜懂添加DTD)

    5、創(chuàng)建action,新建class(命名hello)繼承ActionSupport類,默認(rèn)執(zhí)行ActionSupport的execute() 執(zhí)行成功返回SUCCESS.

    6、在struts.xml中配置action

    <package?name="default"?namespace="/"?extends="struts-default">
    <!--?package?name="default"???是默認(rèn)包名,可以自定義,用于被其他包繼承
    ????????namespace="/"????命名空間,可以指定可以默認(rèn)
    ???????extends="default"????該包所繼承的包
    -->
    ????<action?name="hello"?method=""?class="包全名.hello">
    ????????<result?name="">/result.jsp</result>
    ????????<!--?result?的name默認(rèn)是SUCCESS?也可以是其他action中傳回的字符串?-->
    ????</action>
    </package>

    7、在WebRoot下創(chuàng)建result.jsp

    8、發(fā)布運(yùn)行項(xiàng)目,打開瀏覽器訪問http://localhost:8080/[項(xiàng)目名]/hello.action。

    注:myeclipse最高支持jdk1.7+tomcat7.x

    本機(jī)最初配置是jdk1.8,運(yùn)行項(xiàng)目后報(bào)錯如下

    ????The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files


    查看全部
  • 返回 結(jié)果類型 中的 type

    查看全部
  • 處理結(jié)果類型? result 的type?


    查看全部
  • 處理結(jié)果類型中 :


    局部結(jié)果 <action> 中套入 <result>

    全局結(jié)果 <global-result>?中套入 <result>

    查看全部
  • 在struts2?的結(jié)果類型中?

    使用?result標(biāo)簽?若不填name屬性? ?則采用默認(rèn)值success

    查看全部
  • struts2?返回結(jié)果是字符串 ,

    return "success"? ??

    找到對應(yīng)視圖

    查看全部
  • struts2?調(diào)用方式

    查看全部

舉報(bào)

0/150
提交
取消
課程須知
小伙伴們,學(xué)習(xí)本課程前需要具備Java Web基礎(chǔ),熟悉JSP和Servlet。
老師告訴你能學(xué)到什么?
1、能夠?qū)truts2框架有更深入的了解 2、能夠獨(dú)立編寫Struts2程序

微信掃碼,參與3人拼團(tuán)

微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復(fù)購買,感謝您對慕課網(wǎng)的支持!