Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange Problem with servlet output

 
Rajat Bhatnagar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... or you can place them in the <context>/WEB-INF/lib directory
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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