This week's book giveaway is in the Open Source forum.
We're giving away four copies of RabbitMQ in Depth and have Gavin Roy on-line!
See this thread for details.
The moose likes Servlets and the fly likes Calling Servlet from  a java class  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling Servlet from  a java class  " Watch "Calling Servlet from  a java class  " New topic

Calling Servlet from a java class

Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
Hi Guys,
Hi guys how can I call a servelet in java class when some method in that class finds an exception.
Prasanna KumarBP

Joined: Jul 25, 2001
Posts: 21
write same code, what u do for applets :-)
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
If you mean "can you somehow invoke the service() or doPost()" method to display the results of the error -- the answer is no, you can't do that. You'll have to bubble the exception up to the servlet that originally was called and handle it there.
I think you might have a more interesting question here. Is your question really "how do I handle exceptions in Servlet programming and display errors properly?"
Kyle Brown
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
I agree. Here's the link:
subject: Calling Servlet from a java class