private void doProcess(HttpServletRequest request, HttpServletResponse response)请开启
throws IOException, ServletException {
// set the locale of the user to default if not set
if (request.getsession().getAttribute(WebKeys.LOCALE) == null) {
request.getSession().setAttribute(WebKeys.LOCALE, defaultLocale);
}
try {
getRequestProcessor().processRequest(request);
//进行转导动作(forward)
getScreenFlowManager().forwardToNextScreen(request,response);
} catch (Throwable ex) {
String className = ex.getClass().getName();
String nextScreen = getScreenFlowManager().getExceptionScreen(ex);
// put the exception in the request
request.setAttribute("javax.servlet.jsp.jspException", ex);
if (nextScreen == null) {
// send to general error screen
ex.printStackTrace();
throw new ServletException("MainServlet: unknown exception: " +
className);
}
context.getRequestDispatcher(nextScreen).forward(request, response);
}
}
public void forwardToNextScreen(HttpServletRequest request, HttpServletResponse
response) throws java.io.IOException, FlowHandlerException,
javax.servlet.ServletException {
// set the presious screen
String fullURL = request.getRequestURI();
// get the screen name
String selectedURL = defaultScreen;
int lastPathSeparator = fullURL.lastIndexOf("/") + 1;
if (lastPathSeparator != -1) {
selectedURL = fullURL.substring(lastPathSeparator, fullURL.length());
}
//请加入侦察码,以本例来说,selectedURL=customer.do
System.out.println("selectURL="+ selectedURL);
String currentScreen = "";
URLMapping urlMapping = getURLMapping(selectedURL);
if (urlMapping != null) {
if (!urlMapping.useFlowHandler()) {
currentScreen = urlMapping.getScreen();
//请加入侦察码,以本例来说,currentScreen =customer.screen
System.out.println("currentScreen="+currentScreen);
} else {
// load the flow handler
FlowHandler handler = null;
String flowHandlerString = urlMapping.getFlowHandler();
try {
handler = (FlowHandler)getClass().getClassLoader()
.loadClass(flowHandlerString).newInstance();
// invoke the processFlow(HttpServletRequest)
handler.doStart(request);
String flowResult = handler.processFlow(request);
handler.doEnd(request);
currentScreen = urlMapping.getResultScreen(flowResult);
// if there were no screens by the id then assume that the
result was
//the screen itself
if (currentScreen == null) currentScreen = flowResult;
} catch (Exception ex) {
System.err.println("ScreenFlowManager caught loading
handler: " + ex);
}
}
}
if (currentScreen == null) {
System.err.println("ScreenFlowManager: Screen not found for " +
selectedURL);
throw new RuntimeException("Screen not found for " + selectedURL);
}
//进行转导动作(forward)
System.out.println("forward to "+ currentScreen);
context.getRequestDispatcher("/" + currentScreen).forward(request,
response);
}
<screen name="customer">
<parameter key="title" value="Customer" direct="true"/>
<parameter key="banner" value="/banner.jsp" />
<parameter key="sidebar" value="/sidebar.jsp" />
<parameter key="body" value="/customer.jsp" />
<parameter key="mylist" value="/mylist.jsp" />
<parameter key="footer" value="/footer.jsp" />
</screen>
<table cellpadding="5" cellspacing="0" width="100%" border="0">以下略...
<tr>
<td colspan="3"><p class="petstore_title">Contact Information</p></td>
</tr>
<tr>
<td class="petstore_form" align="right"><b>First Name</b></td>
<td class="petstore_form" align="left"
colspan="2"><c:out value="${customer.account.contactInfo.givenName}"/></td>
</tr>
public void attributeReplaced(HttpSessionBindingEvent se) {以下略...
processEvent(se);
}
private void processEvent(HttpSessionBindingEvent se) {
HttpSession session = se.getSession();
String name = se.getName();
/* check if the value matches the signon attribute
* if a macth fire off an event to the ejb tier that the user
* has signed on and load the account for the user
*/
//判别新增或覆盖属性为”SIGNED_ON_USER”则进行处理,否则略过
if (name.equals(SignOnFilter.SIGNED_ON_USER)) {
boolean aSignOn = ((Boolean)se.getValue()).booleanValue();
if (aSignOn) {
String userName =
(String)session.getAttribute(SignOnFilter.USER_NAME);
//请加入侦察码
System.out.println("SignOnNotifier() userName="+userName);
// look up the model manager and webclient controller
PetstoreComponentManager sl =
(PetstoreComponentManager)session.getAttribute(PetstoreKeys.COMPONENT_MANAGER);
WebController wc = sl.getWebController(session);
SignOnEvent soe = new SignOnEvent(userName);
// set the EJBAction on the Event
EventMapping em = getEventMapping(session.getServletContext(), soe);
if (em != null) {
soe.setEJBActionClassName(em.getEJBActionClassName());
System.out.println("EJBActionClassName="+
em.getEJBActionClassName());
}
try {
//更新资料时会用到,以本例来说只需读取,所以没有作用
wc.handleEvent(soe, session);
} catch (EventException e) {
System.err.println("SignOnNotifier Error handling event " + e);
}
//取得Customer EJB Local Interface Reference
CustomerLocal customer = sl.getCustomer(session);
// ensure the customer object is put in the session
//将Customer EJB Local Interface存入Session
if (session.getAttribute(PetstoreKeys.CUSTOMER) == null) {
session.setAttribute(PetstoreKeys.CUSTOMER, customer);
}
// set the language to the preferred language and other preferences
ProfileLocal profile = sl.getCustomer(session).getProfile();
Locale locale =
I18nUtil.getLocaleFromString(profile.getPreferredLanguage());
session.setAttribute(PetstoreKeys.LOCALE, locale);
}
}
}
D:/petstore1.3.1/src/apps/petstore/src/com/sun/j2ee/blueprints/petstore/controller/web/
PetstoreComponentManager.java,约110列:
public CustomerLocal getCustomer(HttpSession session) {
ShoppingControllerLocal scEjb = getShoppingController(session);
try {
//取得ShoppingClientFacade reference
ShoppingClientFacadeLocal scf = scEjb.getShoppingClientFacade();
//scf.setUserId(userId);
//取得CustomerLocal reference
return scf.getCustomer();
} catch (FinderException e) {
System.err.println("PetstoreComponentManager finder error: " + e);
} catch (Exception e) {
System.err.println("PetstoreComponentManager error: " + e);
}
return null;
}
ShoppingClientFacadeLocalEJB为Session Bean,源码在
D:/petstore1.3.1/src/apps/petstore/src/com/sun/j2ee/blueprints/petstore/controller/ejb/
ShoppingClientFacadeLocalEJB.java,约101列:
/*
* Asume that the customer userId has been set
*/
public CustomerLocal getCustomer() throws FinderException {
//请加入侦察码
System.out.println("ShoppingClientFacadeLocalEJB.getCustomer()");
if (userId == null) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look
up name of customer: userId is not set" );
}
try {
ServiceLocator sl = new ServiceLocator();
CustomerLocalHome home =(CustomerLocalHome)
sl.getLocalHome(JNDINames.CUSTOMER_EJBHOME);
customer = home.findByPrimaryKey(userId);
} catch (ServiceLocatorException slx) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look
up name of customer: caught " + slx);
}
return customer;
}
(出处:http://www.VeVb.com)
新闻热点
疑难解答