Sam,

        There's a lot of things going on in your servlet that you should probably
be aware of.

1- you define the throws clause of dostuff() to throw IOException and
SQLException, but you handle it instead in the dostuff() method.  You might
want to get rid of the SQLException and IOException from the throws and
therefore get rid of it from doGet(), doPost()

2- your dostuff method doesn't appear to be thread safe - at least within
the context of being a servlet.  The only methods that I believe are thread
safe are: doGet(), doPost(), and service().  You might want to look into
synchronizing the method or put the method into the service() method (since
both doGet and doPost call dostuff and service() is really the first method
called prior to calling doGet/doPost (in the super class)

3- get rid of doGet()/doPost() - rename dostuff() to
service(HttpServletRequest req, HttpServletResponse res).  This should
eliminate a lot of your problems

        That's just a few of the things I spotted with your class.  Hope the
critique helps...


                                                                        Erik Sahl
                                                                        
[EMAIL PROTECTED]


> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Sam
> Rose
> Sent: Friday, February 26, 1999 3:09 AM
> To: [EMAIL PROTECTED]
> Subject: Help please - as I'm going crazy
>
>
> Please could someone point out to me exactly where I am going wrong
> with this code. I am trying to put in a finally clause, but it doesn't
> compile, I have tried just about everything.
>
> I would be very grateful if someone could tell me where exactly I'm
> going wrong in my code.
>
>
>
> import java.io.*;
> import java.util.*;
> import java.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class newlite extends HttpServlet {
>
>         public void dostuff (HttpServletRequest req,
> HttpServletResponse res)
>         throws SQLException, ServletException, IOException {
>
>                 HttpSession tsession=req.getSession(true);
>                 res.setContentType("text/html");
>                 PrintWriter os=res.getWriter();
>
> try {   Class.forName( "oracle.jdbc.driver.OracleDriver" );
>                         os.println("<p>");
>                 }
>                 catch (java.lang.ClassNotFoundException e) {
>                         os.print("ClassNotFound: ");
>                         os.println(e.getMessage());
>                 }
>                 try {
>                         con = DriverManager.getConnection();
>                         stmt = con.createStatement();
>
>                 }//endtry
>
>                 catch (java.sql.SQLException ex) {
>                         os.println("SQLExcption: " + ex.getMessage());
>                 }//endcatch
>
>                 finally  {
>                         if (con != null)  {
>                                 con.close(); }//endif
>                         if (stmt != null) {
>                                 stmt.close();}//endif
>                 }//endfinally
>
>
>         }//end dostuff
>
>         public void doGet (HttpServletRequest req,
> HttpServletResponse res)
> throws ServletException, IOException {
>                 dostuff(req, res);
>         }
>
>         public void doPost (HttpServletRequest req,
> HttpServletResponse res)
> throws ServletException, IOException {
>                 dostuff(req, res);
>         }
> }//end
>
> __________________________________________________________________
> _________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to