This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes I don't doGet() it! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "I don Watch "I don New topic
Author

I don't doGet() it!

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
In Servlets 4b there is a puzzle I can't solve in the AddVideoServlet class. This servlet is supposed to display 2 different pages, as I gather from the sample browser pages in the assignment itself. The first page should display the form and the second page displays a message that the video has been added, along with 2 buttons for adding a video or looking at the list of videos. I thought I had this figured out by using doPost to display one page and doGet the other, but now I am getting my sensitive parameters displayed in the address bar from the doGet page. Calling doGet() from inside doPost() just makes the two pages appear at the same time, which I don't want to happen, and the parameters get shown anyway! What's up with that?
Manju Jain
Ranch Hand

Joined: Feb 08, 2001
Posts: 168
You can use doPost to display both the pages. Divide your method into 2 parts with the help of conditional statements. Just evaluate when you'll need to display the main form or the new video added page.
Hope this helps. I don't know whether giving more hints would be appropriate.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
You don't need to use both doGet() and doPost().


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Thanks for your responses.
Manju- I was thinking that was how it would have to be done, but having trouble coming up with a way to do it.
Marilyn- I think I was just being lazy by attempting to build on my previous code instead of starting fresh on this assignment. Back to the drawing board!
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
I checked which button was pressed ...
Manju Jain
Ranch Hand

Joined: Feb 08, 2001
Posts: 168
Carol, initially I faced the same problem. I tried using a static global variable but it was inadvisable by Marilyn. And then I found a way using if else.
Hint: Use removed code first before displaying any of the pages.
[ June 03, 2002: Message edited by: Pauline McNamara ]
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Peter-did you do that with javascript, or is there a way to check which button is clicked using html or regular java code? This question has me stymied.
Manju-I don't see how you can submit the data from the first page to AddVideoServlet and then display
the second page all from doPost() ......wait a minute, if you can check to see if all fields have been completed, then you should be able to display the second page as well, right? I have a page with no links that displays if a required field is left blank. I wonder if the title bar for that page reads AddVideoServlet! Aha! But I can't check right now because I am on the computer at work, and my programs are at home!!! RATS!!!
P.S. Thanks!
[ June 01, 2002: Message edited by: Carol Murphy ]
[ June 01, 2002: Message edited by: Carol Murphy ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
No javascript (I don't know javascript). Your buttons have different names and different values.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Actually, my buttons didn't have names, although they did have values. Now that they have names, I think I can solve this problem!
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Indeed no javascript here. The "different" buttons are indeed the clue
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I don't doGet() it!
 
Similar Threads
Please Help ! Applet to Servlet : Content is not updated? Suspect browser cache
generic servlet vs http servlet
Reverse2Servlet doXxx( question )
doGet() calling doPost() problem -- URL line visible in destination page!
Servlet - doGet - doPost - parameter