Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes request.getParameter() and JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParameter() and JavaScript" Watch "request.getParameter() and JavaScript" New topic

request.getParameter() and JavaScript

Jolly Khanna

Joined: Sep 24, 2001
Posts: 12
In my jsp page, I'm setting the value of a hidden textbox and I'm trying to retrieve the contents of that text box in a Servlet using request.getParamter, but I'm getting "null" as a result. First I set the value of the hidden paramter in javascript. I don't use an "action" for my form. Instead I use location.href in javascript. Can someone PLEASE help?
Here is the JSP page:
function setValue(str1, str2)
{ = str2
location.href = "/myPage/" + str1;
</javascript >
<form name="test"><input type=hidden name="name" value="">
</form >
<a on_click = "setValue('Hello', 'World');" Click me!</a >
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63869

Well Jolly, I'm not sure how the Request.getParameter() fits into all this since you mention it in your message, but do not reference it anywhere in your example code. But, I think the javascript you want is more along the lines of:

This probably should be moved to the Javascript forum.

[Asking smart questions] [About Bear] [Books by Bear]
Jolly Khanna

Joined: Sep 24, 2001
Posts: 12
Hey Bear,
Thanks for your help.
The request.getParameter() was being used to set the value of "name" to an object. In my Servlet I was calling String name = request.getParameter("name"); but the value was coming up null.
I agree. Here's the link:
subject: request.getParameter() and JavaScript
It's not a secret anymore!