aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Hyperlink to Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Hyperlink to Servlet" Watch "Hyperlink to Servlet" New topic
Author

Hyperlink to Servlet

Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
I currently have a doPost defined in a servlet which works perfectly but on my jsp I have a "NEXT and BACK" hyperlink that I would like to go to that same servlet and return to the page just altering what is shown on the page. My problem is that I still need all the form parameters that are passed with a normal <form submit>. I've debated just



but I'm not too fond of this idea.

I've never used javaScript but have heard good things ;). So I was looking into:


...which to my understanding submits the form with all of its parameters.
So, my question is how would I send a new form parameter inside the JavaScript just to tell the servlet whether it was "BACK or NEXT"?
[ May 14, 2008: Message edited by: paul yule ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Add a hidden element to the form. Set the value to whatever you want prior to submission.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

P.S. If you're not going to use the link as a link, I wouldn't use the <a> tag at all. You can put an onclick handler on a <span> and style it to look however you like. That way you avoid any interference between the semantics of the link and your JavaScript.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
Ok, thanks. I'm currently having a different error with it now. I decided to just use the link but I got rid of the onClick (and I'll prolly go to a <span> once I get it functional). This is currently what I've got:



Yet, the request inside the doGet() method has a null parameter list.
[ May 14, 2008: Message edited by: paul yule ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Hmmm, and the form is getting submitted to the servlet ok?

I'm actually a little surprised that anything works as the document.form notation is rather old-fashioned and naming the form "form" may run into reserved word issues (Hint; never name anything "submit"!)

But if the form is invoking the servlet...

At this point I'd probably use a tool like TamperData to see what's actually being submitted by the browser.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
Well, the form actually doesn't seem to be submitted at all. None of the parameters are present from the JSP. I'm a little perplexed myself. It is getting to the doGet() method inside my servlet but when I try to pull anything off the request it throws a NPE. I use fireBug to watch the javaScript and it's going inside the function. This would be my first stab at js so...

It is my understanding that the whole page is a document object and there is an array of forms that belong to it such that you could access them via document.forms[] inside your JS.

to which i tried:


In doing this I also changed the method to POST which worked correctly but again inside the doPost the request.Parameter list was null. So, the only thing it appears not to be doing is submitting the form.

Sigh, I'm so confused
[ May 14, 2008: Message edited by: paul yule ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Originally posted by paul yule:
It is my understanding that the whole page is a document object and there is an array of forms that belong to it such that you could access them via document.forms[] inside your JS.

While I'm certain it's not the cause of your woes, that's a very old-fashioned (and error prone) way to address form elements. Modern patterns use the id attribute and document.getElementById().

Maybe it's time to show us how your form is declared.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229


p.s. I started working on something else yesterday and when I came back to it today it worked just peachy...WTT my left arm for updated tools PST
[ May 15, 2008: Message edited by: paul yule ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Sounds like a caching issue.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
Sounds like a caching issue.


my thoughts exactly.
 
 
subject: Hyperlink to Servlet