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.
manoj r patil
Ranch Hand
Joined: Jun 06, 2002
Posts: 180
posted
0
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?
love your job and not your company;
...because you never know when your company will stop loving you!
tangara goh
Ranch Hand
Joined: Dec 27, 2009
Posts: 125
posted
0
I only have one servlet inside. ...it's just a simple program....also I'm not using eclipse...just using IDE...that's all.
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.
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
Joined: Dec 27, 2009
Posts: 125
posted
0
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
Joined: Dec 27, 2009
Posts: 125
posted
0
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.
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.
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.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
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.
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
Joined: Dec 27, 2009
Posts: 125
posted
0
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
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
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.
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
Joined: Dec 27, 2009
Posts: 125
posted
0
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
Joined: Jun 06, 2002
Posts: 180
posted
0
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
Joined: Dec 27, 2009
Posts: 125
posted
0
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.
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
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
And THAT is why I do not recommend that beginners start learning servlets with an IDE.
Bill (the old curmudgeon)
tangara goh
Ranch Hand
Joined: Dec 27, 2009
Posts: 125
posted
0
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.
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
Joined: Dec 27, 2009
Posts: 125
posted
0
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?