my dog learned polymorphism
The moose likes Servlets and the fly likes Strange Problem with servlet output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Strange Problem with servlet output " Watch "Strange Problem with servlet output " New topic

Strange Problem with servlet output

Rajat Bhatnagar

Joined: Mar 11, 2008
Posts: 22
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()

Here's my Code

package com.encore;
import javax.servlet.*;
import javax.servlet.http.*;
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;
PrintWriter pw = response.getWriter();

//Oracle Database Connection Starts
try {
//Load and Register the oracle driver

//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("Inside the Database Servlet class");
while( )) {
pw.println("<LI>"+rs.getString("name")+ " " + rs.getString("phone"));
catch(SQLException se){
System.out.println("SQL Exception rajat:" + se.getMessage());

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

//Oracle Database connection ends
finally {
try {
}catch(SQLException ignored){}

Regards<br />Rajat Bhatnagar<br /><a href="" target="_blank" rel="nofollow"></a>
Rajat Bhatnagar

Joined: Mar 11, 2008
Posts: 22
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

i placed the jars there stopped and started the service and bingo Output is there in the browser.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

... or you can place them in the <context>/WEB-INF/lib directory
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130

But then, your logs should have shown classNotFoundException...?
How about this..?

Durga Prasad
I agree. Here's the link:
subject: Strange Problem with servlet output
jQuery in Action, 3rd edition