Thanks Henric for answering my questions. I am wondering what is the difference
between ServletOutputStream and getWriter(). I learned from the Servlet
Programming book the following code. I thought that is the only way to output
stuff.
Could you enlighten me why you would use one way verus the other? Thanks.
public class HelloWorld extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String sName[] = req.getParameterValues("name");
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello, " + sName[0] + "</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello, </BIG>" + sName[0]);
out.println("<P>User Agent = " + req.getHeader("User-Agent") );
out.println("</BODY></HTML>");
}
Henric Larsson <[EMAIL PROTECTED]> on 04/20/99 11:08:47 AM
Please respond to "A mailing list for discussion about Sun Microsystem's Java
Servlet API Technology." <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Sin Lam/Whittman-Hart LP)
Subject: Re: PROBLEM WITH SERVLETS(DATABASE)
sos object is the ServletOutputStream, the object that you write your output to.
you get it by calling response.getOutputStream();
.henric
----- Original Message -----
From: Sin Lam <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 20, 1999 4:40 PM
Subject: Re: PROBLEM WITH SERVLETS(DATABASE)
What is sos object? I don't see it defined in the original source below. Why
do you have to flush it?
--------------------------------------------------------------------------------
��äȯ <[EMAIL PROTECTED]> on 04/20/99 08:19:49 AM
Please respond to "A mailing list for discussion about Sun Microsystem's Java
Servlet API Technology." <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Sin Lam/Whittman-Hart LP)
Subject: Re: PROBLEM WITH SERVLETS(DATABASE)
--------------------------------------------------------------------------------
You have to flush the sos object. This is the modified source.
while(rs.next())
{
String str=rs.getString(1);
res.setContentType("text/html");
sos.println("the user_id is "+str);
}
}
catch(Exception e)
{ }
sos.flush(); // added line
sos.close(); // added line
}
}
================================
Korea Telecom Chungbuk branch
Chaehwan Im
[EMAIL PROTECTED]
Phone:82-2-0431-210-5126~8
================================
-----
--------------------------------------------------------------------------------
���� ����-----
���� ���: thumma sunil <[EMAIL PROTECTED]>
�� ���: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
��¥: 1999�� 4�� 20�� ȭ���� ���� 7:54
����: PROBLEM WITH SERVLETS(DATABASE)
>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
>
___________________________________________________________________________
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