You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Emyr James <em...@OrbisUK.com> on 2002/05/15 13:09:30 UTC
Error Handling
Dear all,
I'm writing a servlet application using velocity under tomcat. At the moment I'm
doing something like this...
public class MyServlet extends VelocityServlet {
public Template handleRequest( HttpServletRequest request, HttpServletResponse
response, Context context ){
Template template=null;
try {
//stuff that may throw an error
} catch( Exception e ) {
context.put("error",e.toString());
try {
template=getTemplate("error.vm");
} catch( Exception ee ) {
ee.printStackTrace();
System.exit(0);
}
}
return template;
I want to make this complete by changing the System.exit(0) stuff to send stuff
back on the servlets output stream directly, circumventing velocity entirely.
How can I get access to this stuff so that the servlet behaves like a typical
servlet under certain circumstances.
Cheers,
Emyr
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Error Handling
Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 5/15/02 7:09 AM, "Emyr James" <em...@OrbisUK.com> wrote:
> Dear all,
> I'm writing a servlet application using velocity under tomcat. At the moment
> I'm
> doing something like this...
>
> public class MyServlet extends VelocityServlet {
> public Template handleRequest( HttpServletRequest request,
> HttpServletResponse
> response, Context context ){
> Template template=null;
> try {
> //stuff that may throw an error
> } catch( Exception e ) {
> context.put("error",e.toString());
> try {
> template=getTemplate("error.vm");
> } catch( Exception ee ) {
> ee.printStackTrace();
> System.exit(0);
> }
> }
> return template;
>
> I want to make this complete by changing the System.exit(0) stuff to send
> stuff
> back on the servlets output stream directly, circumventing velocity entirely.
> How can I get access to this stuff so that the servlet behaves like a typical
> servlet under certain circumstances.
That's easy : just use the request/response objects as normal, and return
null.
When the baseclass sees the 'null' returned, it assumes you took care of the
request, and does nothing else.
--
Geir Magnusson Jr.
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>