亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

Struts Action 控制器

genedna / 3302人閱讀

摘要:請(qǐng)參閱許可證管理權(quán)限和限制的特定語(yǔ)言根據(jù)許可證。行動(dòng)執(zhí)行成功但沒(méi)有顯示一個(gè)視圖。這對(duì)于有效的操作很有用以重定向等其他方式處理視圖。表示執(zhí)行邏輯結(jié)果的字符串。如果發(fā)生系統(tǒng)級(jí)異常,則拋出異常。注意應(yīng)通過(guò)返回來(lái)處理應(yīng)用程序級(jí)異常錯(cuò)誤值,例如。

控制器

即,mvc模型的控制器模型,用于接收數(shù)據(jù),傳遞給視圖層,和模型層
默認(rèn)使用execute方法

查看相關(guān)接口

查看com.opensymphony.xwork2下的Action接口
文件如下

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.opensymphony.xwork2;

/**
 * All actions may implement this interface, which exposes the execute() method.
 * 

* However, as of XWork 1.1, this is not required and is only here to assist users. You are free to create POJOs * that honor the same contract defined by this interface without actually implementing the interface. *

*/ public interface Action { /** * The action execution was successful. Show result * view to the end user. */ public static final String SUCCESS = "success"; /** * The action execution was successful but do not * show a view. This is useful for actions that are * handling the view in another fashion like redirect. */ public static final String NONE = "none"; /** * The action execution was a failure. * Show an error view, possibly asking the * user to retry entering data. */ public static final String ERROR = "error"; /** *

* The action execution require more input * in order to succeed. * This result is typically used if a form * handling action has been executed so as * to provide defaults for a form. The * form associated with the handler should be * shown to the end user. *

* *

* This result is also used if the given input * params are invalid, meaning the user * should try providing input again. *

*/ public static final String INPUT = "input"; /** * The action could not execute, since the * user most was not logged in. The login view * should be shown. */ public static final String LOGIN = "login"; /** * Where the logic of the action is executed. * * @return a string representing the logical result of the execution. * See constants in this interface for a list of standard result values. * @throws Exception thrown if a system level exception occurs. * Note: Application level exceptions should be handled by returning * an error value, such as Action.ERROR. */ public String execute() throws Exception; }

大概翻譯一下

 *
?*獲得Apache軟件基金會(huì)(ASF)的許可
?*或更多貢獻(xiàn)者許可協(xié)議。請(qǐng)參閱NOTICE文件
?*與此工作一起分發(fā)以獲取更多信息
?*關(guān)于版權(quán)所有權(quán)。 ASF許可此文件
?*根據(jù)Apache許可證2.0版(
?* “執(zhí)照”);除非符合規(guī)定,否則您不得使用此文件
?*使用許可證。您可以在以下位置獲取許可證副本
?*
?* http://www.apache.org/licenses/LICENSE-2.0
?*
?*除非適用法律要求或書(shū)面同意,
?*根據(jù)許可證分發(fā)的軟件分發(fā)在
?*“按原樣”基礎(chǔ),不提供任何保證或條件
?* KIND,無(wú)論是明示的還是暗示的。請(qǐng)參閱許可證
?*管理權(quán)限和限制的特定語(yǔ)言
?*根據(jù)許可證。
?* /
package com.opensymphony.xwork2;

/ **
?*所有動(dòng)作可能實(shí)現(xiàn)此接口,該接口公開(kāi) execute()方法。
?* 

?*但是,從XWork 1.1開(kāi)始,這是必需的,僅用于幫助用戶。您可以自由創(chuàng)建POJO ?*遵守此接口定義的相同合同而不實(shí)際實(shí)現(xiàn)接口。 ?* ?* / public interface Action { ????/ ** ?????*行動(dòng)執(zhí)行成功。顯示結(jié)果 ?????*查看最終用戶。 ?????* / ????public static final String SUCCESS =“success”; ????/ ** ?????*行動(dòng)執(zhí)行成功但沒(méi)有 ?????*顯示一個(gè)視圖。這對(duì)于有效的操作很有用 ?????*以重定向等其他方式處理視圖。 ?????* / ????public static final String NONE =“none”; ????/ ** ?????*行動(dòng)執(zhí)行失敗。 ?????*顯示錯(cuò)誤視圖,可能會(huì)詢問(wèn) ?????*用戶重試輸入數(shù)據(jù)。 ?????* / ????public static final String ERROR =“error”; ????/ ** ?????*

?????*動(dòng)作執(zhí)行需要更多輸入 ?????*為了成功。 ?????*此結(jié)果通常用于表格 ?????*處理行動(dòng)已經(jīng)執(zhí)行 ?????*提供表單的默認(rèn)值。該 ?????*與處理程序關(guān)聯(lián)的表單應(yīng)該是 ?????*向最終用戶顯示。 ?????* ?????* ?????*

?????*如果給定輸入,也會(huì)使用此結(jié)果 ?????*參數(shù)無(wú)效,意味著用戶 ?????*應(yīng)該嘗試再次提供輸入。 ?????* ?????* / ????public static final String INPUT =“input”; ????/ ** ?????*行動(dòng)無(wú)法執(zhí)行,因?yàn)??????*用戶最多未登錄。登錄視圖 ?????*應(yīng)該顯示。 ?????* / ????public static final String LOGIN =“l(fā)ogin”; ????/ ** ?????*執(zhí)行動(dòng)作的邏輯。 ?????* ?????* @return表示執(zhí)行邏輯結(jié)果的字符串。 ?????*有關(guān)標(biāo)準(zhǔn)結(jié)果值的列表,請(qǐng)參閱此界面中的常量。 ?????* @throws如果發(fā)生系統(tǒng)級(jí)異常,則拋出異常。 ?????* 注意:應(yīng)通過(guò)返回來(lái)處理應(yīng)用程序級(jí)異常 ?????*錯(cuò)誤值,例如 Action.ERROR 。 ?????* / ????public String execute()拋出異常; }

可以看到,定義了幾個(gè)常量一個(gè)接口,其中默認(rèn)執(zhí)行execute方法,其中幾個(gè)常量為執(zhí)行結(jié)果的常量

擴(kuò)展實(shí)現(xiàn)Action接口的ActionSupport類
/**
 * Provides a default implementation for the most common actions.
 * See the documentation for all the interfaces this class implements for more detailed information.
 */
public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable

大概翻譯一下

*為最常見(jiàn)的操作提供默認(rèn)實(shí)現(xiàn)。
? *有關(guān)更多詳細(xì)信息,請(qǐng)參閱此類實(shí)現(xiàn)的所有接口的文檔。
?*/

所以直接擴(kuò)展該類即可

重新擴(kuò)展HelloWorldAction
package com.ming;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {
    private String name;

    @Override
    public String execute() throws Exception {
        return "success";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

可以在execute中書(shū)寫(xiě)業(yè)務(wù)邏輯
重新更改如下

package com.ming;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {
    private String name;

    @Override
    public String execute() throws Exception {
        if(SUCCESS.equals(name)){
            // 此時(shí)返回SUCCESS
            return SUCCESS;
        }else{
            // 其余內(nèi)容返回error
            return ERROR;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

在上方,根據(jù)name的值,完成了一個(gè)業(yè)務(wù)邏輯,返回是 or 否

編寫(xiě)配置文件





    
    
    
    
        
        
            
            /HelloWorld.jsp
            /error.html
        
    
效果如下

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/73929.html

相關(guān)文章

  • Struts2 入門 1

    摘要:是的下一代產(chǎn)品,是在和的技術(shù)基礎(chǔ)上進(jìn)行了合并的全新的框架。其全新的的體系結(jié)構(gòu)與的體系結(jié)構(gòu)差別巨大。以為核心,采用攔截器的機(jī)制來(lái)處理用戶的請(qǐng)求,這樣的設(shè)計(jì)也使得業(yè)務(wù)邏輯控制器能夠與完全脫離開(kāi),所以可以理解為的更新產(chǎn)品。 Struts是什么 概念 Struts2是一個(gè)基于MVC設(shè)計(jì)模式的Web應(yīng)用框架,它本質(zhì)上相當(dāng)于一個(gè)servlet,在MVC設(shè)計(jì)模式中,Struts2作為控制器(Cont...

    tabalt 評(píng)論0 收藏0
  • SpringMVC入門就這么簡(jiǎn)單

    摘要:也就是說(shuō)映射器就是用于處理什么樣的請(qǐng)求提交給處理。這和是一樣的提交參數(shù)的用戶名編號(hào)提交配置處理請(qǐng)求注冊(cè)映射器包框架接收參數(shù)設(shè)置無(wú)參構(gòu)造器,里邊調(diào)用方法,傳入要封裝的對(duì)象這里的對(duì)象就表示已經(jīng)封裝好的了對(duì)象了。 什么是SpringMVC? SpringMVC是Spring家族的一員,Spring是將現(xiàn)在開(kāi)發(fā)中流行的組件進(jìn)行組合而成的一個(gè)框架!它用在基于MVC的表現(xiàn)層開(kāi)發(fā),類似于struts...

    SKYZACK 評(píng)論0 收藏0
  • 面試題:SpringMVC和Struts2的區(qū)別

    摘要:的入口是,而是這里要指出,和是不同的。以前認(rèn)為是的一種特殊,這就導(dǎo)致了二者的機(jī)制不同,這里就牽涉到和的區(qū)別了。開(kāi)發(fā)效率和性能高于。的實(shí)現(xiàn)機(jī)制有以自己的機(jī)制,用的是獨(dú)立的方式。 1、Struts2是類級(jí)別的攔截, 一個(gè)類對(duì)應(yīng)一個(gè)request上下文,SpringMVC是方法級(jí)別的攔截,一個(gè)方法對(duì)應(yīng)一個(gè)request上下文,而方法同時(shí)又跟一個(gè)url對(duì)應(yīng),所以說(shuō)從架構(gòu)本身上SpringMVC...

    isaced 評(píng)論0 收藏0
  • Struts2開(kāi)發(fā)流程

    摘要:的開(kāi)發(fā)流程在文件中定義核心攔截用戶請(qǐng)求。的最大作用是配置和請(qǐng)求之間的對(duì)應(yīng)關(guān)系,并配置邏輯視圖名和物理視圖資源之間的相對(duì)關(guān)系,即返回結(jié)果和文件的物理位置的關(guān)系。實(shí)現(xiàn)為了使開(kāi)發(fā)的更規(guī)范,提供了一個(gè)接口,定義了的處理應(yīng)該實(shí)現(xiàn)的規(guī)范。 1.struts2的開(kāi)發(fā)流程 在web.xml文件中定義核心Filter攔截用戶請(qǐng)求。 struts2 org.apa...

    Leo_chen 評(píng)論0 收藏0
  • Struts2入門這一篇就夠了

    摘要:現(xiàn)在,我們使用了的話,那么框架內(nèi)部就能幫我們封裝了。每個(gè)中都有和這樣的方法,沒(méi)必要的。我們抽取出來(lái),通過(guò)配置文件來(lái)把這兩個(gè)方法替換掉,那么我們的程序就會(huì)更加優(yōu)雅了。于是乎,就應(yīng)運(yùn)而生了。因此,學(xué)習(xí)的時(shí)候,不了解是沒(méi)有任何關(guān)系的。 前言 這是Strtus的開(kāi)山篇,主要是引入struts框架...為什么要引入struts,引入struts的好處是什么,以及對(duì)Struts2一個(gè)簡(jiǎn)單的入門.....

    Scliang 評(píng)論0 收藏0
  • Struts2開(kāi)發(fā)入門指南

    摘要:作為一個(gè)開(kāi)發(fā)框架,它為我們很好的提供了一個(gè)開(kāi)發(fā)模板,使用可以減輕開(kāi)發(fā)人員的負(fù)擔(dān)并且可以增強(qiáng)程序的可讀性,下面我們來(lái)說(shuō)說(shuō)如何使用做一個(gè)小例子開(kāi)發(fā)所需要的工具開(kāi)發(fā)環(huán)境開(kāi)發(fā)的包一個(gè)文檔模板開(kāi)發(fā)開(kāi)發(fā)分為以下四步完成導(dǎo)入相應(yīng)的包在文檔中配置的核 **Struts2**作為一個(gè)開(kāi)發(fā)框架,它為我們很好的提供了一個(gè)開(kāi)發(fā)模板,使用**Struts2**可以減輕開(kāi)發(fā)人員的負(fù)擔(dān)并且可以增強(qiáng)程序的可讀性,下面...

    notebin 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<