aspose file tools*
The moose likes Cattle Drive and the fly likes doGet() but I don'tGet() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "doGet() but I don Watch "doGet() but I don New topic
Author

doGet() but I don'tGet()

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Got this nitpick on my last attempt:
MVC2 requires that rather than call the jsp directly, this call should go to the servlet first.

My app was working, but I had an anchor tag in one jsp going directly to another jsp without going to the servlet first.
So I'm trying to route this request through the servlet, but there are a few things I just don't get.
1) doGet() and doPost() are final methods in the parent class of my servlet. I'm not exactly sure how I got the first version to work now(!?!) without overriding doGet() or doPost(), but I did.
2) I just read in one of books today that the target of an anchor tag in html is always fetched by doGet().
3) Since I can't override doGet() because of its final nature, are links just not the way to go here?
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Okay. Just when I thought I had a handle on this servlet stuff, poof! it disappears.
I switched the method from get to post by changing the link to a button. The form sends a parameter that tells the servlet to pick the right method. Can I send an action parameter with a doGet() request? Because I would like to keep the listvideo.jsp page in the same exact format as the sample, which means calling the addvideo.jsp via my servlet using the doGet() that an href link uses. However, the logic I put in my servlet doesn't want to work for doGet(). I get a null pointer exception, or it doesn't work at all. A blank page. doPost() works just like I want it to. In fact, switching the link to a button that sends data from a form works. How do i do that with a get request?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Sorry, Carol. I overlooked this thread yesterday.

When you call doGet or doPost on a servlet that extends ActionServlet, you first go to the init() method. In the init method the addActionHandler() defines where the call is going to go by matching the parameter you sent. The only difference between handling the doGet and the doPost is the way the parameter is passed.

I suggest that you read up on how to pass parameters using doGet.


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: 1197
Perhaps I'm overlooking something, but the only way I have found to pass parameters with a get or a post is by using a form, which means a submit button. Is there a way to pass parameters with a link?
The way I have my init set up, if the request is using get, there is no way for the servlet to decide which jsp to forward it to because without submitting from a form, no parameters are sent with the request, even though they exist on the page. Should I put something in the headers that would tell the servlet which jsp I want the request forwarded to? Or is there a way to send parameters along with the request when using an anchor tag to link to a page?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Originally posted by Carol Murphy:
Is there a way to pass parameters with a link? ... is there a way to send parameters along with the request when using an anchor tag to link to a page?

Yes there is a way to do that.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Originally posted by Marilyn de Queiroz:
[QB]...
In the init method the addActionHandler() defines where the call is going to go by matching the parameter you sent. ...QB]


Okay, one of my ActionHandlers has a matching parameter, and it behaves as expected. The other one has no matching parameter, but it gets called anyway. How come?

And I will keep searching for a way to pass parameters with an href link. If it's out there, I will find it.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Okay. I tried appending the name/value pair I wanted to send as a parameter to my servlet to the url, but the servlet still can't read the parameter. I've called the getParameter() method in the same fashion as I did for the post method, but it doesn't want to work.
Also, I've noticed that addvideo.jsp has an action parameter built into it, and I used the value for that as the first argument to one of my addActionHandler() methods in init(). The second addActionHandler() was being called even though there was no other parameter named action with the value I was using as the first argument! Thinking that might be part of the problem, I changed it to match the value of the action parameter I'm trying to pass with the hyperlink, but the parameter never arrives at the servlet, or the servlet can't read what it is getting. I tested my code by setting the value for the parameter inside the class, and it worked like I was hoping it would by forwarding the request to the right jsp. Now, the big question is why won't the servlet get the parameter?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Okay. I tried appending the name/value pair I wanted to send as a parameter to my servlet to the url, but the servlet still can't read the parameter. I've called the getParameter() method in the same fashion as I did for the post method, but it doesn't want to work.

I'm not clear on why you want to use getParameter(). I would think that all you want your new class to do is forward to the jsp.

Also, I've noticed that addvideo.jsp has an action parameter built into it, and I used the value for that as the first argument to one of my addActionHandler() methods in init(). The second addActionHandler() was being called even though there was no other parameter named action with the value I was using as the first argument! Thinking that might be part of the problem, I changed it to match the value of the action parameter I'm trying to pass with the hyperlink, but the parameter never arrives at the servlet, or the servlet can't read what it is getting. I tested my code by setting the value for the parameter inside the class, and it worked like I was hoping it would by forwarding the request to the right jsp. Now, the big question is why won't the servlet get the parameter?

Would you please post your init method here?
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Originally posted by Marilyn de Queiroz:


Would you please post your init method here?


Gladly. Here it is:

public void init()
{
addActionHandler( "list" , new VideoList() ) ;
addActionHandler( "add a new video" , new Add() ) ;
}

One of the ActionHandler names is supplied by addvideo.jsp, the other was actually never supplied by any parameter I could find in my source code, so I figured there must be a default ActionHandler that was calling that one. Any way, the parameter issue was solved by Ben Souther in the servlets forum and I've sent my latest attempt off to you via email!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doGet() but I don'tGet()