Go-ForIt 记事:eXtreme DragonSlayers 专题报告,第 8 部分: 陷入多级显示漩涡
2009-11-06 00:00:00 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鐐劤缂嶅﹪寮婚悢鍏尖拻閻庨潧澹婂Σ顔剧磼閹冣挃闁硅櫕鎹囬垾鏃堝礃椤忎礁浜鹃柨婵嗙凹缁ㄧ粯銇勯幒瀣仾闁靛洤瀚伴獮鍥敍濮f寧鎹囬弻鐔哥瑹閸喖顬堝銈庡亝缁挸鐣烽崡鐐嶆棃鍩€椤掑嫮宓佸┑鐘插绾句粙鏌涚仦鎹愬闁逞屽墰閹虫捇锝炲┑瀣╅柍杞拌兌閻ゅ懐绱撴担鍓插剱妞ゆ垶鐟╁畷銉р偓锝庡枟閻撴洘銇勯幇闈涗簼缂佽埖姘ㄧ槐鎾诲礃閳哄倻顦板┑顔硷工椤嘲鐣烽幒鎴旀瀻闁规惌鍘借ⅵ濠电姷鏁告慨顓㈠磻閹剧粯鈷戞い鎺嗗亾缂佸鏁婚獮鍡涙倷閸濆嫮顔愬┑鐑囩秵閸撴瑦淇婇懖鈺冪<闁归偊鍙庡▓婊堟煛鐏炵硶鍋撻幇浣告倯闁硅偐琛ラ埀顒冨皺閺佹牕鈹戦悙鏉戠仸闁圭ǹ鎽滅划鏃堟偨缁嬭锕傛煕閺囥劌鐏犻柛鎰ㄥ亾婵$偑鍊栭崝锕€顭块埀顒佺箾瀹€濠侀偗婵﹨娅g槐鎺懳熺拠鑼舵暱闂備胶枪濞寸兘寮拠宸殨濠电姵纰嶉弲鎻掝熆鐠虹尨宸ョ€规挸妫濆铏圭磼濡搫顫嶇紓浣风劍閹稿啿鐣烽幋锕€绠婚悹鍥у级瀹撳秴顪冮妶鍡樺鞍缂佸鍨剁粋宥夋倷椤掍礁寮垮┑鈽嗗灣閸樠勭妤e啯鍊垫慨妯煎亾鐎氾拷

servlet 将这个视图 bean 存储在 HttpServletRequest 对象中。我们把它存储在 HttpServletRequest 对象中,是因为这个视图列表仅对这个请求有用。下次显示列表时,差事的状态可能已经改变了,必须使用更新的差事列表将新的视图 bean 实例化。
servlet 将控制权转移给 JSP 以显示数据。
The pa_errands_edit JSP 从存储在 HttpServletRequest 对象中的 bean 取出 HTML,将其放入页面中。
此页面被返回给浏览器,PA 查看差事列表。 HttpServletRequest 对象和视图 bean HTML 被删除。 HttpSession 对象以及存储在这个对象中的用户和列表 bean 仍保留了下来以便下一次请求使用。
我们的实现使用客户端 bean(用户实现用 UserDataBean ,差事列表实现用 ErrandListBean )和一个视图 bean。
下一部分讨论 servlet 和 JSP 代码以及它们对 HttpSession 和 HttpServletRequest 的使用。
显示差事代码
下面是执行这项工作的 performTask 方法的 servlet 代码,这段样本代码后面有关于代码的讨论。
EditPAErrandsServlet、performTask 方法public void performTask(
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res) {
UserDataBean user = new UserDataBean();
PersonalAssistantDataBean pa = null;
ErrandListBean paErrandList = null;
HttpSession session = null;
GetPAErrandsCommandBean dataCommand = new GetPAErrandsCommandBean();
/* ******************* START OF BLOCK 1 ************/
try {
/*
* Get the existing user info from the session.
* (false) indicates we expect the session to be there - if
* not, do not create a new sesssion.
*/
session = req.getSession(false);
if (session != null) {
user = (UserDataBean) session.getValue("user");
}
/*
* No session, go to login
*/
if (user == null) {
getServletConfig()
.getServletContext()
.getRequestDispatcher("/index.jsp")
.forward(req, res);
/* ******************* START OF BLOCK 2 ************/ }
/*
* Retrieve the data if the errandList in the session is
* null. Otherwise just use it.
*/
paErrandList = (ErrandListBean) session.getValue("paErrandList");
if (paErrandList == null) {
/* No ErrorListBean, so retrieve errands.
*/
try {
dataCommand.setPaId(user.getUserid());
dataCommand.execute();
paErrandList = dataCommand.getPaErrands();
} catch (CommandException e2) {
/*
* All other command errors go to the error page
*/
req.setAttribute("errorMsg", new ErrorView(e2.getMessage()));
req.setAttribute("user", user);
getServletConfig()
.getServletContext()
.getRequestDispatcher("/pages/error.jsp")
.forward(req, res);
return;
}
}
/* ******************* START OF BLOCK 3 ************/
/* Forward to JSP to display editable form */
if (paErrandList != null) {
// Convert the ErrandList into an HREF list for the JSP
req.setAttribute("ErrandListView", new
GetErrandListHTMLView(paErrandList));
// put the paErrandList to the session object
session.putValue("paErrandList", paErrandList);
}
/* Forward to the JSP */
getServletConfig()
.getServletContext()
.getRequestDispatcher("pages/pa_errand_list_paonly.jsp")
.forward(req, res);
} catch (Throwable t) {
try {
req.setAttribute("errorMsg", new ErrorView(t.getMessage()));
req.setAttribute("user", user);
getServletConfig()
.getServletContext()
.getRequestDispatcher("/pages/error.jsp")
.forward(req, res);
} catch (Exception e) {
log(e.getMessage());
}
}
}
- ››Godaddy域名解析使用DNSPOD方法
- ››GOV.CN域名解析修改
- ››Google搜索引擎的奥秘
- ››Google测试搜索结果页面右侧内容更丰富的信息栏
- ››Google Dart精粹:应用构建,快照和隔离体
- ››google的代码审查
- ››google analytics清晰追踪爬虫的爬行信息
- ››Google+中文用户在两千万Google+大军中是少数派
- ››Google AdWords最昂贵点击成本的20种关键词分类
- ››Google运作经理Bryan Power给出的GOOGLE求职意见
- ››Google用户体验的十大设计原则
- ››Google Analytics(分析)能为网站带来什么
更多精彩
赞助商链接