Hi,
If you extend javax.servlet.http.HttpServlet then is better to
overwrite doGet() and/or doPost() calls instead of service().
...
Then response.setContentType("text/html") needs (must) to be called
only once, **before** writing any data to the output
req.getOutputStream(). And even better before you requested it:
first:
req.setContentType(...);
then:
sos = req.getOutputStream()
.. connect..
.. print querry back to the "sos" ..
----------------
All these because when you start to write at output stream
the servlet engine is no more able to change the content-type.
.....
If you want to see more about what is wrong is also good, at least
at development/testing stage to do something usefull with
the exception catched at the bottom of service call -
..
catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
Is far better than to ignoring it with:
catch (Exception e) { }
...
Will spare you a lot of questions/answers/puzlle-ing..
Bye.
Cezar
On Tue, 20 Apr 1999, thumma sunil wrote:
> hello everybody iam sunil
>
> i have a problem with servlets(database).i had compiled the source
> code successfully and placed the class file in the servlets dir of
> javawebserver1.1.3 which i had downloaded from java.sun.com
> the problem is whenever iam loading the file on the browser iam
> getting
> a message box that NO DOCUMENTS FOUND is appearing on the browser
> netscape navigator 4.0 .
> this problem is for only for servlets that are trying to connect to
> the database. other servlets(other than the database) are working
> normally
> could any one can help me?
> source code hope this is correct
> import java.io.*;
> import java.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class user extends HttpServlet
> {
> Statement st;
> public void service(HttpServletRequest req,HttpServletResponse
> res)
> {
>
> try
> {
> ServletOutputStream sos=res.getOutputStream();
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> // databse is msaccess
> Connection
> con=DriverManager.getConnection("jdbc:odbc:sunil");
> st=con.createStatement();
> ResultSet rs=st.executeQuery("Select * from log");
> while(rs.next())
> {
> String str=rs.getString(1);
> res.setContentType("text/html");
> sos.println("the user_id is "+str);
> }
> }
> catch(Exception e)
> { }
> }
> }
>
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> ___________________________________________________________________________
> 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
>
Cezar Totth email: [EMAIL PROTECTED]
Fax: (401) 220 33 95
Genesys Software Romania Phone: (401) 638 49 44
Stefan Furtuna 169, sect.6
cod 77171, Bucharest
Romania
___________________________________________________________________________
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