01.01.2013 Views

CICS Transaction Gateway V5 The WebSphere ... - IBM Redbooks

CICS Transaction Gateway V5 The WebSphere ... - IBM Redbooks

CICS Transaction Gateway V5 The WebSphere ... - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

366 <strong>CICS</strong> <strong>Transaction</strong> <strong>Gateway</strong> <strong>V5</strong><br />

catch (Throwable t)<br />

{<br />

// exception occured, set exception message in request with timestamp<br />

String nowStr = "";<br />

try<br />

{<br />

SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getTimeInstance();<br />

sdf.applyPattern("MM/dd/yy HH:mm:ss:SSS");<br />

nowStr = sdf.format(new Date());<br />

}<br />

catch(ClassCastException ex2)<br />

{<br />

// no SimpleDateFormat instance for this locale<br />

}<br />

// format with Date toString<br />

nowStr = (new Date()).toString();<br />

}<br />

request.setAttribute(attrErrorException, nowStr + " : " + t);<br />

// change jsp to use to the error jsp<br />

jsp = jspError;<br />

Figure B-28 Handling exceptions in the execute() method<br />

<strong>The</strong> final section of code in the processRequest() method forwards to the<br />

appropriate JSP, set in the instance variable jsp (Figure B-29).<br />

finally<br />

{<br />

// route to jsp<br />

ServletContext servletContext = getServletContext();<br />

RequestDispatcher dispatcher = servletContext.getRequestDispatcher(jsp);<br />

dispatcher.forward(request, response);<br />

}<br />

Figure B-29 Routing to a JSP<br />

We get the ServletContext object that represents the current request and<br />

response. We then get the RequestDispatcher object for the selected JSP from<br />

the ServletContext. <strong>The</strong> forward() method is called on the RequestDispatcher,<br />

passing in the HttpRequest and HttpResponse. This causes the request to be<br />

forwarded to the JSP, with the objects representing details of the session. <strong>The</strong><br />

JSP will then generate the response HTML.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!