日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

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

半翻譯半整理的一些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 />標簽即可。

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

本類教程下載

系統下載排行

主站蜘蛛池模板: 99久久er这里只有精品17 | 99这里只有精品66视频 | 88国产经典欧美一区二区三区 | 91在线精品播放 | 久久精品国产99精品最新 | 精品的一区二区三区 | 色婷婷香蕉 | 99久久综合精品免费 | 天天夜夜久久 | 国产天堂在线观看 | 久久精品影院永久网址 | 国产日韩高清一区二区三区 | 天堂网在线www资源在线 | 中文字幕无线精品乱码一区 | 久草丝袜| 欧美日韩不卡高清 | 韩日精品在线 | 亚洲精品美女久久777777 | 色5月综合 | 日本黄视色视频在线观看 | 日韩激情无码免费毛片 | 久久91亚洲精品中文字幕 | 亚洲日本欧美 | 欧美一级久久久久久久久大 | 亚洲成年人视频 | 狠狠操天天操视频 | 竹菊影视一区二区三区 | 天天色天天干天天 | 久久精品免费视频观看 | 最新高清无码专区 | 亚洲精品香蕉婷婷在线观看 | 免费岛国小视频在线观看 | 国产成人精品日本亚洲语言 | 最新国产成人综合在线观看 | 欧洲色吧 | 国产精品视频a播放 | 亚洲日韩精品欧美一区二区一 | 亚洲国产综合精品中文字幕 | 久草在线免 | se999se男人最爱| 亚洲欧美综合一区 |