• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Java servlet neither runs nor shows any error. Just shows blank page in browser

 
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

This is my first java servlet & jsp program. There are two pages- registration form with INSERT / doPost() method and the second one is view record page with SELECT/ doGet() method. Register page has a form that accepts and inserts record and view_record is a page that displays all records using SELECT query.

Register page works fine and adds record to SQL database but when I try to run view_record (servlet page) in browser through NetBeans, it gives me a blank screen with servlet page's directory path. No error, no warning nothing, just a blank page. see the attached screenshot.

Any idea why is this happening? I tried this on multiple computers but didn't work on any.

OS: Windows Vista 32 bit.
IDE: Netbeans
Database: MysQL (Using MySQL Workbench)

Here is my code:

index.html



Servlet code (page name: register.java)



Code for view_record servlet (view_record.java) - this is what not working



Strange thing is I don't get any error in code or on browser and yet this does not work. It should show up the records in a tabular format but instead it only shows blank screen with Servlet's directory path on the screen.
srvlt.jpg
[Thumbnail for srvlt.jpg]
Servlet page showing blank page upon running.
 
Greenhorn
Posts: 7
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Code Ranch

Please do replace line 70 of view_record servlet by

Class.forName("com.mysql.jdbc.Driver");
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First thing is do not create HTML in Servlet. You got JSPs for view.
If you are not getting the desired output, trace it from the query output.
Have you printed the "id" in console and run the query in MySql by replacing "?" by "id". Is it giving desired output?
Have you checked the control coming inside the while loop by putting some console outputs?
 
Moin Shaikh
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Das Verma wrote:Welcome to Code Ranch

Please do replace line 70 of view_record servlet by

Class.forName("com.mysql.jdbc.Driver");



Thank you for the warm welcome

I replaced that connection string but still the same blank screen.

Sorry but I have no idea why this is happening.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the source html produced.

I'm looking at the servlet code posted and you are, in the processRequest method, sending an entire page to the client.
After that you then attempt to send more stuff (after the </html>). I doubt the client will display that.


Having said that, why does the code you posted have a different title ("Servlet search_record) than that displayed in your image?
 
Moin Shaikh
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Look at the source html produced.

I'm looking at the servlet code posted and you are, in the processRequest method, sending an entire page to the client.
After that you then attempt to send more stuff (after the </html>). I doubt the client will display that.


Having said that, why does the code you posted have a different title ("Servlet search_record) than that displayed in your image?



My bad , I pasted wrong code. I actually created search_record page for testing purpose after this view_record didn't work.

The code for view_record is here:

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you check the html on the client?

This is what the processRequest method will have sent, before you do any database stuff:

You then do the rest of the doGet method, and attempt to construct a table.

So check the html in your browser.
There may well be a table there.
 
Moin Shaikh
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Did you check the html on the client?

This is what the processRequest method will have sent, before you do any database stuff:

You then do the rest of the doGet method, and attempt to construct a table.

So check the html in your browser.
There may well be a table there.



Thank you Dave,

I got it. It should be a full html table code to display the tabular format (the code that is in the doGet() method), correct?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you did as Tapas said and did the display part in a JSP then you would avoid all these problems.

The immediate fix might be to remove the </html> part from processRequest, though I expect you might find other problems.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't close the servlet response output stream, it does not flush the last buffer and you get a blank screen.

Get familiar with the "view source" capability of your browser for questions like this.

Bill
 
Moin Shaikh
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you gentlemen for all your guidance, I am checking whole of my code and fixing it as suggested here. I need to learn so many basic Java things but this is beginning and I am confident that I will overcome this kinda mistakes.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic