This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Study kit-error attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Study kit-error attributes" Watch "Study kit-error attributes" New topic

Study kit-error attributes

Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
)The following example is from study kit

we use a RequestDispatcher to include or forward a request to another
resource. We can also use it to forward a request to an error page. The following code
for the doPost() method illustrates this approach:
public void doPost(HttpServletRequest req,
HttpServletResponse res)
String command = req.getParameter("command");
double amount =
String accountId =
double newBalance = debit(accountId, amount);
catch(InsufficientFundsException isfe)
req.setAttribute("javax.servlet.error.exception", isfe);
RequestDispatcher rd = req.getRequestDispatcher(
rd.forward(req, res);
//generate HTML page showing new balance.
//do something else

Do we need to explicitly set these attributes in the catch block above.Wont it be set automatically by the container?
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

They will be set by the container is the error has been handled by the container. For example, an uncaught exception. Here, you explicitly forward to the error servlet, so the container will do nothing else than forwarding the request.

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Study kit-error attributes
It's not a secret anymore!