• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange Problem with servlet output

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have written a Servlet which talks to the database fetches some data and prints it out in the browser.I was successfully able to compile the servlet class but when i deploy the same in tomcat a blank screen occurs.

I checked the table in the database.It has some records.
web.xml is perfectly fine and the utl-pattern perfect.
I checked tomcat logs.But they are also perfect.
However i did not have any luck with the output and always see a BLANK SCREEN
javascript: x()
banghead


Here's my Code

package com.encore;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class FileUploadServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException {

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
response.setContentType("text/html");
PrintWriter pw = response.getWriter();

//Oracle Database Connection Starts
try {
//Load and Register the oracle driver
Class.forName("oracle.jdbc.driver.OracleDriver");

//Get a connection to the database
conn = DriverManager.getConnection("jdbc racle:thin:@kaikeyee:1521:enr9i","TNS51628","TNS51628");

//Create a Statement object
stmt = conn.createStatement( );

//Execute a SQL statement , get a resultset
rs = stmt.executeQuery("select name,phone from employees");

//Display the result set as a list
pw.println("<html><head><title>PhoneBook</title></head>");
pw.println("<body>");
pw.println("Inside the Database Servlet class");
pw.println("<ul>");
while(rs.next( )) {
pw.println("<LI>"+rs.getString("name")+ " " + rs.getString("phone"));
}
pw.println("</ul>");
pw.println("</body></html>");
}
catch(SQLException se){
System.out.println("SQL Exception rajat:" + se.getMessage());
se.printStackTrace(System.out);

}
catch(ClassNotFoundException cnfe){
System.out.println("ClassNotFounException found");
}

//Oracle Database connection ends
finally {
try {
if(conn!=null){
conn.close();
}
}catch(SQLException ignored){}
}
}
}
 
Rajat Bhatnagar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all

Javaranch is kind of lucky..

Figured out the problem a moment ago


We need to place the database specific jars in Tomcat 5.5\common\lib
directory...

i placed the jars there stopped and started the service and bingo Output is there in the browser.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... or you can place them in the <context>/WEB-INF/lib directory
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But then, your logs should have shown classNotFoundException...?
How about this..?
 
reply
    Bookmark Topic Watch Topic
  • New Topic