Click to See Complete Forum and Search --> : servlet Not Running


October 7th, 1999, 11:15 AM
Hi folks ,
When I compile the servlet ,no error.
But When I open it in the browser nothing coming and when I see the viewsource following error is coming.
plese help
san
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD>
<BODY></BODY></HTML>



import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class Demo1 extends HttpServlet
{
ResultSet rs;

Statement stmt;
Connection con;
/*public void init(ServletConfig config) throws ServletException
{
super.init(config);


}

public void destroy()
{

super.destroy();
}*/

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
PrintWriter out = new PrintWriter(resp.getOutputStream());

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:PERDET");
stmt = con.createStatement();

rs = stmt.executeQuery("select * from EMPLOYEE");

out.println("<HTML>");
out.println("<HEAD><TITLE>Employee details</TITLE></HEAD>");
out.println("<BODY>");
out.println("asdfasdf");
//out.close();
out.println("<UL>");

while(rs.next())
{

out.println("<LI>" + rs.getString("NAME") + " "+rs.getString("SALARY")+ " " +rs.getString("DOB"));
}
out.println("</UL>");

out.println("</BODY>");
out.println("</HTML>");
out.close();
} catch(Exception e) {e.printStackTrace();}

finally
{
try
{
if (con != null) con.close();

}catch (Exception e) {e.printStackTrace();}

}
}


}

amaresh
October 7th, 1999, 12:32 PM
I am not sure abt the error. How did you make out the error from the source? Is it wrong HTML? Or different one from what you expected?
Please see what the "java console" of your browser says (if at all it does :-) ) and post that.
Thanks,
Amaresh

October 7th, 1999, 01:52 PM
hi amaresh,

When I compile the servlets ,it's successfully built.,When I open the class file ,Iam not getting anything.
Then I right clicked the mouse to view the source in that page.Iam getting that info(that is the source generated by the servlet).
please give me the solution and what is the problem in the servlet.
regs
san

amaresh
October 7th, 1999, 02:11 PM
I understand that there are no compilation errors. But inorder to find the run time error, I suggest that you open
the "java console" in your browser and post whatever you find there. Open the "java console" in your browser,
and then access the servlet. Then you will see lot of text(exceptions etc) getting diplayed in the java console window.
Please post that here. That will help me to guess what exactly is going on ..
Thanks,
Amaresh

October 7th, 1999, 02:32 PM
Some small points. My guess is u r using Netscape browser. Do the following
take the result set outputs seperately in variables and then print the list item.
Secondly, try closing all tags. <li> with </li> etc. Try out and see. This might work.

Bhanu Erraguntla
October 7th, 1999, 02:39 PM
Reposting this mail again

Some minor points. I guess u r using Netscape browser. Try doing some small changes.
First, take the data from all the columns into variables and then add to the list. Check for nulls
Using rs.wasNull() after each getString and then substitute them with "".
Secondly, close all tags <li> with </li>. Try this out. It might work.

Shan
October 7th, 1999, 03:36 PM
Hi amaresh,
I could not find "java console" in the browser .Iam using both IE &netscape.
Please reply for this.
regs
san

amaresh
October 7th, 1999, 04:07 PM
In Netscape, go to the menuitem "Communicator - Tools - Java Console"
In IE, choose the menu "View - Java Console".
In IE, if you don't see the menu item "Java Console" under the menu "View", it means you have not enabled that option. To enable it,
choose "View - Internet Options". You will see a tabbed dialog on the screen. Now click on the tab "Advanced". If you keep scrolling,
you will see a check box "Java Console Enabled".Check that box and restart your IE browser. Now you will see the "Java Console" menu
item under "View" menu in IE.
Thanks,
Amaresh

Shan
October 7th, 1999, 04:25 PM
hi amaresh,
I solved the problem.I didn't closed the o/p stream.
but this is the info that I got it from "java console".Thanks a lot for your help.
thanks and regs
shan

_____________
Netscape Communications Corporation -- Java 1.1.5
Type '?' for options.
Symantec Java! ByteCode Compiler Version 210.065
Copyright (C) 1996-97 Symantec Corporation