• 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

Why Servlet return a blank page?

 
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I created a form and then processed it.

Before I process, I debug both the form and the servlet. No errors.

But, when I filled up the form which has a post to a servlet.

The servlet gives me a blank page...as in the tomcat server gives me a blank page in my browser.

By right, it is supposed to give me a statement that says "records successfully added" and my ms access database will be updated with the new records. None of these happen.

Hope to hear why.

Thanks.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you verify that its calling the correct servlet?

When you said "I debug both the form and the servlet", I expect you did it at runtime uaing some IDE like eclipse. So was the code executing your business logic?
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I only have one servlet inside. ...it's just a simple program....also I'm not using eclipse...just using IDE...that's all.

Any idea where I had gone wrong?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you perhaps printing to System.out? You shouldn't, servlets have their own output stream which you can get using the servlet response's getPrintWriter (for text) or getOutputStream (for binary data) methods. Just don't use both methods in the same servlet.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using out.println.....as per my partial code below. Anything wrong with using that?



ps.setString(9, strFrequency);
for (int i=0; i < strTutors.length; i++){
ps.setString(10, strTutors[i]);
}
ps.setString(11, strBudget);
ps.setString(12, strRemarks);
ps.executeUpdate();
response.setContentType("text/html");
out.println("Member account has been created"); [/code]

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're giving us almost no information to work with. How about using DEBUG-level log statements and checking the logs???
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in your form are you using POST or GET, and which method did you implement in your servlet, doPost or doGet?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:

Are you aware that you are overwriting the 10th parameter each time? You might as well write "ps.setString(10, strTutors[strTutors.length - 1]);"
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hongli Li wrote:in your form are you using POST or GET, and which method did you implement in your servlet, doPost or doGet?



In my form, I'm using Post.

In my servlet, I have used the overriding method over do Get and do Post, because I was told that this way works. Is it wrong?


As shown here,


 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:

tangara goh wrote:

Are you aware that you are overwriting the 10th parameter each time? You might as well write "ps.setString(10, strTutors[strTutors.length - 1]);"



I'm not aware of this.


In my form, I have checked boxes and user may tick as many checked boxes so the parameters will read whatever ticked boxes and parsed it into the database.





Is the codes wrong?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:Is the codes wrong?


Yes.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. It must be the servlet that is wrong right?

So, I'll have to follow Rob Prime's suggestion then.

O my......I'm like hopeless when comes to something that I'm not familiar with.....Can somebody enlighten me how you guys learn programming?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're missing Rob's point--you're trying to stuff several values into a single column: it doesn't work like that. If a user can have multiple subjects then in general you'd need another table that either has a user id/subject, or a mapping table of user id/subject id.

How to learn how to program? Program a lot. Read a lot about programming. Read other people's code, and try to improve it. Practice, practice, practice.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:In my servlet, I have used the overriding method over do Get and do Post, because I was told that this way works. Is it wrong?


Wait, what's processRequest? I don't see it in HttpServlet.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because it isn't. In fact, all of JEE's API knows no such method. There is the service method that can be overridden, but HttpServlet subclasses should override doGet or doPost instead.
 
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
One of the best ways to learn servlets and jsp is to study the examples that come with Tomcat.

Try modifying them to see what happens so that you are starting with working code. Modifying working code is much better than trying to write a whole new servlet or jsp.

As I recall, one way to get a blank page response is to fail to flush and close the output stream.

Bill
 
Hongli Li
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:
In my servlet, I have used the overriding method over do Get and do Post, because I was told that this way works. Is it wrong?



There are fundamental differences in POST and GET, GET is idempotent, which means no more you call it once or many times, the side effects to the server will be the same. and POST is not. When you are retrieving data from server, GET is the one you should use, When you are inserting data you POST. PUT is for updating and DELETE for removal.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, thank you guys for pointing out so many of my mistakes....looks like I have to pore over the books for the fundamental again.

There's this book that I just read - Better, Faster, Lighter Java by Bruce A.Tate & Justin Gehtland,2004. Not sure if the book is outdated but one of the chapters recommend using Hibernate.


There are only 5 basic steps involved. I find it something that looks easy...correct me if I'm wrong.

However, the book only illustrates a simple example. And I'm not sure how to start.

I hope to know what are the books or websites I can study for beginner like me.

Also, is it foolish to jump to Hibernate when I haven't even really grasp the basic JDBC using Tomcat?

Really hope you guys can share with me your views. Many thanks.
 
William Brogden
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
Just to repeat myself, study the examples that Tomcat comes with.

I heartily recommend using the FireFox browser with the plugins such as FireBug and LiveHTTPHeaders - they will show you what is really going on if you get a "blank page" or any other mystery on the client side.

Bill
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:Also, is it foolish to jump to Hibernate when I haven't even really grasp the basic JDBC using Tomcat?


Yes. How will you debug Hibernate issues if you don't understand the underlying technology?
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:Just to repeat myself, study the examples that Tomcat comes with.

I heartily recommend using the FireFox browser with the plugins such as FireBug and LiveHTTPHeaders - they will show you what is really going on if you get a "blank page" or any other mystery on the client side.

Bill



OK. I searched for the examples inside my IDE but can't find the examples.

I doubt you are talking about the contents under the Help tab inside the IDE....could you be more explicit whereabout I can find the examples? Many thanks.
 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:I searched for the examples inside my IDE but can't find the examples.



Why are you checking in IDE? Its been clearly told that the examples are distributed along with Tomcat. Run tomcat as a standalone server and visit its home page, you should be able to see those examples unless you have custom installation.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

manoj r patil wrote:

tangara goh wrote:I searched for the examples inside my IDE but can't find the examples.



Why are you checking in IDE? Its been clearly told that the examples are distributed along with Tomcat. Run tomcat as a standalone server and visit its home page, you should be able to see those examples unless you have custom installation.



Please bear with my ignorance for I always have this thinking that Tomcat server is inside every Netbean IDE and so I looked inside IDE.


Is this the URL you are referrring to ?
http://tomcat.apache.org/

but I can't find any examples you mentioned. When I clicked on the Java server pages, it brought me to Oracle page.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the Tomcat download.

That aside, there are hundreds, if not thousands, of Java web application tutorials and examples on the web, including Sun's (Oracle's) own tutorials.

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/WebApp.html

It'll be really, really, *really* important to learn how to learn about these things, how to find examples, how to read forums to find solutions, etc. It's also very important to have strong fundamentals: without them, little else will make sense, and when things go cow's legs up, not knowing how to examine the various layers involved will make it literally impossible to figure out what's gone wrong.
 
William Brogden
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
And THAT is why I do not recommend that beginners start learning servlets with an IDE.

Bill (the old curmudgeon)
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:In the Tomcat download.

That aside, there are hundreds, if not thousands, of Java web application tutorials and examples on the web, including Sun's (Oracle's) own tutorials.

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/WebApp.html

It'll be really, really, *really* important to learn how to learn about these things, how to find examples, how to read forums to find solutions, etc. It's also very important to have strong fundamentals: without them, little else will make sense, and when things go cow's legs up, not knowing how to examine the various layers involved will make it literally impossible to figure out what's gone wrong.



Thank you David. The link you provided is got lots of information. Thank you very much.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:And THAT is why I do not recommend that beginners start learning servlets with an IDE.

Bill (the old curmudgeon)



But, is there any other way to execute the servlet without IDE? I don't think notepad ++ can allow servlet to run right?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:But, is there any other way to execute the servlet without IDE? I don't think notepad ++ can allow servlet to run right?


And this is why William recommends against IDEs.

You run Tomcat (or other container) as a real server rather than relying on an IDE to do it for you.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Tangara,


First of all read all concept of servlet and after that try to run existing example.
Then you will not get this type of problems.









 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Hijack removed. Please ask your own questions in your own new topic.]
reply
    Bookmark Topic Watch Topic
  • New Topic