This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Strange Problem with servlet output " Watch "Strange Problem with servlet output " New topic
Author

Strange Problem with servlet output

Rajat Bhatnagar
Greenhorn

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()
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){}
}
}
}


Regards<br />Rajat Bhatnagar<br /><a href="http://guideofgreatness.googlepages.com" target="_blank" rel="nofollow">http://guideofgreatness.googlepages.com</a>
Rajat Bhatnagar
Greenhorn

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
directory...

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

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..?


Regards,
Durga Prasad
 
wood burning stoves
 
subject: Strange Problem with servlet output
 
Similar Threads
retreiving all rows from a mysql table to a jsp page
Servlet connection with Jdbc
validation problem using jsp,servlets,ms-access db
database connection in servlet on Tomcat 5.5
cannot find symbol