Reverse2Servlet doXxx( question )
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have Reverse2Servlet working as requried, but the only way I could find to do so was to override multiple doXxx() methods. This seems silly to me since one of them can only be used once. Is there a way to make the one that gets used all the other times handle the initial request? The way I tried it I got a standard no body HTML page that must have come out of LogServlet...
Wait a minute, I'm trying to think of something clever to say...<p>Joel
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Matthew Phillips
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
allow me to ask my question more bluntly and a friendly neighborhood bartender can edit my post if needs be...I had to use a doGet() method to handle the initial page request (i.e. the one with a non existent form) and then a doPost() method to handle the same request with a populated form. What I'm trying to ask, is there a way to get the doPost() method to handle the inital page request so that I don't have to override both methods???
Wait a minute, I'm trying to think of something clever to say...<p>Joel
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Since you are hitting the servlet the first time via the URL, this is a GET request from your browser, no way around it, at least from everything I have read/done. A POST request has to be specified, since GET is the "default" request method, and you specify it by declaring it in your form.
If there is some way to force a POST request in this situation, I'd love to hear about it!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Joel Cochran:
I had to use a doGet() method to handle the initial page request (i.e. the one with a non existent form) and then a doPost() method to handle the same request with a populated form.
I assume that non existant form means empty form, right? There's a hint in the assignment about the form:
"You can set the contents of an HTML input tag by introducing the value attribute:
<input type=text name=text value="spooooooon!" size=50 >"
Using that hint is key to this assignment.
As far as the doXXX methods go, remember that you can treat both requests and responses with one doXXX.
Maybe that helps?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-

-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by jason adam:
Ah, now I see what you are asking.
Since you are hitting the servlet the first time via the URL, this is a GET request from your browser, no way around it, at least from everything I have read/done. A POST request has to be specified, since GET is the "default" request method, and you specify it by declaring it in your form.
If there is some way to force a POST request in this situation, I'd love to hear about it!
This is a common issue with Servlets and the usual solution I've been exposed to calls doPost from doGet.
Nothing wrong with this, especially if the code for both GET/POST method calls is identical or makes more sense when combined.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This is a common issue with Servlets and the usual solution I've been exposed to calls doPost from doGet.
I'm in no way doubting that that's a valid solution, but I just want to point out that you can also create a third method that both doPost and doGet call.
I tend to think of doPost and doGet as being special in the sense that they should be called only by the servlet container.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Pauline McNamara:
I assume that non existant form means empty form, right? There's a hint in the assignment about the form:
"You can set the contents of an HTML input tag by introducing the value attribute:
<input type=text name=text value="spooooooon!" size=50 >"
Using that hint is key to this assignment.
As far as the doXXX methods go, remember that you can treat both requests and responses with one doXXX.
Maybe that helps?
Actually, I mean a non-existent form. When you type code removed - bad dog! in the address line of your browser there is no form to submit, so the Servlet assumes a GET method. What I was hoping to do was find a more elegant solution than overriding both methods.
Thanks for the hint, but I got all that already, now I'm just nitpicking myself!

[ May 15, 2002: Message edited by: Pauline McNamara ]
Wait a minute, I'm trying to think of something clever to say...<p>Joel
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What he was ASKING is if you can just override one without having to call one from the other. In other words, make the initial call to a webpage go directly to doPost() without the intermediate call to doGet().
[ May 14, 2002: Message edited by: jason adam ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by jason adam:
In other words, make the initial call to a webpage go directly to doPost() without the intermediate call to doGet().
Sure you can. But the assignment tells you not to.
Michael "gotta try out this subtlety thing" Matola
[ May 14, 2002: Message edited by: Michael Matola ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The second most common technique I've seen has doGet and doPost call a third method, like Matola suggested
. For simple Servlets I don't think this is necessary.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What I was hoping to do was find a more elegant solution than overriding both methods.
Thanks for the hint, but I got all that already, now I'm just nitpicking myself!
Sorry, didn't mean to be insulting, wasn't sure just where you were stuck. In addition to the comments above, the link in Matthew's post (above) discusses some of the elegance question.
[ May 15, 2002: Message edited by: Pauline McNamara ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Michael Pearson:
The second most common technique I've seen has doGet and doPost call a third method, like Matola suggested. For simple Servlets I don't think this is necessary.
Not that I have much experience with servlets to base it on, but the last discussion about which way makes more sense was enough to convince me that calling a third doStuff from doPost and doGet seems more logical.
Why not for simple servlets too?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Good luck on your own choice

-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Pauline McNamara:
Not that I have much experience with servlets to base it on, but the last discussion about which way makes more sense was enough to convince me that calling a third doStuff from doPost and doGet seems more logical.
Why not for simple servlets too?
To me it seems "procedural" to drive all of the activity into a single doXXX method. I'm not saying I have a preference, just sharing what I've noticed.
[ May 15, 2002: Message edited by: Michael Pearson ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
) for having almost duplicate code, but I guess we'll wait and see.Thanks everyone!
Wait a minute, I'm trying to think of something clever to say...<p>Joel
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you call doPost() from inside doGet() and there are paramters to be passed that you wish to remain a secret, will your secret be exposed by calling doPost this way, and is there a way to avoid this exposure???
Not that i'm thinking of any particular assignment, whistle, whistle nonchalantly.......

-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Calls to doPost do not show form data in the request header, it is sent on a separate data line.
Calls to doGet show form data in the request header.
If you want to keep all of your form data hidden, like a password, call doPost and let it call doGet if you need to support both GET and POST methods.
</guru:not>
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
doGet() inside of doPost(), the seconde page appears on teh first page and I don't want it there!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Michael Pearson:
To me it seems "procedural" to drive all of the activity into a single doXXX method. I'm not saying I have a preference, just sharing what I've noticed.
Procedural? How so?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Michael Matola:
Procedural? How so?
All depends on how the code is written.
If a servlet is set up as a Controller to forward to other Servlets/JSPs that is great.
When Servlet requests get forwarded from doGet and doPost to a single doXXX method there is a chance some "procedural" infrastructure will be created.
It's pretty easy to see:
(1) poor cohesion or
(2) tight coupling
creep into Servlet development if good OOAD is not used.
You know there are people in the "real world" that write applications like Servlet-5 in one Servlet without thinking twice about it. Just because Java is an OO language doesn't mean you can't create very procedural code.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
By having doGet and doPost call a third method, you actually gain a design benefit. If you ever need one of the methods to handle things differently, you just change that method. If you place all of your code in doPost and then have doGet call it and later need to change what doPost does, you run into a little trouble.
Matthew Phillips
| Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ... Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |






