• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當前位置:雨林木風下載站 > 技術開發(fā)教程 > 詳細頁面

        半翻譯半整理的一些struts的東東,很淺顯的,歡迎指正(4)

        半翻譯半整理的一些struts的東東,很淺顯的,歡迎指正(4)

        更新時間:2022-04-26 文章作者:未知 信息來源:網絡 閱讀次數:

        二、出錯管理(Managing Errors)
        Struts框架有兩個主要的類來管理出錯,一個是org.apache.struts.action.ActionError類,它對錯誤信息進行包裝。另一個是org.apache.struts.action.ActionErrors類,它是ActionError實例的容器。這兩個類經常要在ActionForm及Action類中使用。其具體的使用如下:
        ActionErrors errors = new ActionErrors();
        errors.add("propertyname", new ActionError("key");
        errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("key");
        關于"propertyname"和ActionErrors.GLOBAL_ERROR,對前者用在ActionForm中,這里是對應表現層(JSP)中的屬性值。而對后者則用在Action中,它對應struts-config.xml的<global-forwards />中描述的信息。例子:
        ActionForm類:
        public class LoginForm extends ActionForm {
        …………………
        public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if ( (username == null ) || (username.length() == 0) ) {
        errors.add("username",new ActionError("errors.username.required"));
        }
        if ( (password == null ) || (password.length() == 0) ) {
        errors.add("password",new ActionError("errors.password.required"));
        }
        return errors;
        }
        …………………
        }

        Action類:
        public class LoginAction extends Action {
        ……………………
        public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponseresponse) throws IOException, ServletException {
        String user = null;
        // Default target to success
        String target = "success";
        // Use the LoginForm to get the request parameters
        String username = ((LoginForm)form).getUsername();
        String password = ((LoginForm)form).getPassword();
        user = getUser(username, password);
        // Set the target to failure
        if ( user == null ) {
        target = "login";
        ActionErrors errors = new ActionErrors();
        errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("errors.login.unknown",username));
        // Report any errors we have discovered back to the
        // original form
        if (!errors.empty()) {
        saveErrors(request, errors);
        }
        }
        else {
        HttpSession session = request.getSession();
        session.setAttribute("USER", user);
        }
        // Forward to the appropriate View
        return (mapping.findForward(target));
        }
        }
        在表現層中表現錯誤只須要寫上<html:error />標簽即可。

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統(tǒng)下載排行

        主站蜘蛛池模板: 国产精品永久免费视频| 亚洲精品无码永久在线观看男男| 一级毛片大全免费播放| 日韩免费视频网站| 久久亚洲色WWW成人欧美| 亚洲精品国产品国语在线| 丰满少妇作爱视频免费观看| 又粗又大又长又爽免费视频| 亚洲国产精品一区| 久久这里只精品国产免费10| 免费不卡中文字幕在线| 美女扒开尿口给男人爽免费视频 | 久久亚洲精品无码av| 好吊妞在线新免费视频| 无码一区二区三区亚洲人妻| 免费中文字幕不卡视频| 国产午夜精品理论片免费观看| 亚洲AV永久纯肉无码精品动漫| 亚洲AV成人片无码网站| 哒哒哒免费视频观看在线www| 一级毛片aa高清免费观看| 亚洲午夜久久久影院伊人| 国产青草亚洲香蕉精品久久| xvideos亚洲永久网址| 久久九九久精品国产免费直播| 亚洲AV乱码久久精品蜜桃| 久草在视频免费福利| 国产亚洲美女精品久久久久| 亚洲国产一二三精品无码| 免费能直接在线观看黄的视频| 婷婷亚洲综合五月天小说 | 无码中文字幕av免费放| 色婷婷六月亚洲综合香蕉| 亚洲无人区午夜福利码高清完整版| 麻豆成人久久精品二区三区免费| 亚洲日本在线电影| 亚洲桃色AV无码| 成人毛片18女人毛片免费96| 9久久免费国产精品特黄| 亚洲中文字幕无码av永久| 亚洲欧洲日产国码无码网站 |