Hi Raphael, you could use an intermediate base servlet in your app,
something like:

public abstract class BaseServlet extends HttpServlet
 {
  public void doPost(HttpServletRequest request,
                         HttpServletResponse response)
   throws ServletException, IOException
   {
    try
     {
      doPostInternal(request,response);
     }
    catch(Exception e)
     {
      request.setAttribute("my_servlet_exception",e);
        //forward request to error.jsp using a dispatcher
     }
   }

  protected abstract void doPostInternal(HttpServletRequest request,
                                                     HttpServletResponse
response)
   throws Exception;
 }


Your selectdetail class (better SelectDetail) will become:

public class selectdetail extends BaseServlet
 {
  protected void doPostInternal(HttpServletRequest request,
                                        HttpServletResponse response)
   throws Exception
   {
    //Do something, throwing SQLException if a DB error occours.
   }
 }


And your error.jsp will read "my_servlet_exception" attribute from the
request and will manage it.


Regards
Alessio


-----Messaggio originale-----
Da: Chetan Wagle [mailto:[EMAIL PROTECTED]]
Inviato: venerd́ 3 maggio 2002 11.07
A: Tomcat Users List
Oggetto: Re: How to add a throw exception to a servlet


Hi Raphel,

    Can you let me know why you have this peculiar requirement of 
changing the signature of the doPost method ?

Rgds,
Chetan

___________________________________________________________________________
 
Chetan Wagle
Project Manager
Capstone IT Technologies Pvt. Ltd.
 
www.capstoneit.com

TeleFax: +91 (0)40 6786951
Email  : [EMAIL PROTECTED]
___________________________________________________________________________


Legally privileged/Confidential Information may be contained in this 
message. If you are not the addressee(s) legally indicated in this message 
(or responsible for delivery of the message to such person), you may not
copy or deliver this message to anyone. In such case, you should destroy 
this message, and notify us immediately. If you or your employer does not 
consent to Internet e-mail messages of this kind, please advise us 
immediately. Opinions, conclusions and other information expressed in this 
message are not given or endorsed by my firm or employer unless otherwise 
indicated by an authorised representative independent of this message. 
Please note that despite using the latest virus software, neither my 
employer nor I accept any responsibility for viruses and it is your 
responsibility to scan attachments (if any).
 

Raphael wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>The doPost method of a servlet looks like this :
>
>public class selectdetail extends HttpServlet {
>    public void doPost(HttpServletRequest request,
>                      HttpServletResponse response)
>       throws ServletException, IOException {
>
>What if in my doPost method I am using Object methods that throw other 
>exceptions, like SQLException. The Java compiler would not let me write :
>
>public void doPost(HttpServletRequest request,
>                      HttpServletResponse response)
>       throws ServletException, IOException,SQLException
>
>But I want the exception to be caught in the error.jsp page, not do a try 
>{...} catch{...} inside the doPost body.
>
>I don't know if I explained it correctly but is there a simple solution to 
>this problem ?
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.6 (GNU/Linux)
>Comment: For info see http://www.gnupg.org
>
>iD8DBQE80Sfrh2ITK4xBkFERAgMfAJ95HwnlLTICnfOeOrK33jifllqhtACdFrXN
>xtFJ/YRjwGEqQNESeKRTrAE=
>=IMF1
>-----END PGP SIGNATURE-----
>
>
>--
>To unsubscribe:   <mailto:[EMAIL PROTECTED]>
>For additional commands: <mailto:[EMAIL PROTECTED]>
>Troubles with the list: <mailto:[EMAIL PROTECTED]>
>
>
>

-- 


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>



- Disclaimer -
This email and any attachments thereto may contain information which is
confidential and/or protected by intellectual property rights and are
intended for the sole use of the recipient(s) named above. Any use of the
information contained herein (including, but not limited to, total or
partial reproduction, communication or distribution in any form) or the
taking of any action in reliance on the contents, by persons other than the
designated recipient(s) is strictly prohibited.

If you have received this email in error, please notify the sender either by
telephone or by email and delete the material from any computer.

Thank you for your cooperation. 



--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to