• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hyperlink to Servlet

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add a hidden element to the form. Set the value to whatever you want prior to submission.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a caching issue.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sounds like a caching issue.



my thoughts exactly.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic