This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes passing parameter from js to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing parameter from js to servlet" Watch "passing parameter from js to servlet" New topic
Author

passing parameter from js to servlet

santu Naid
Greenhorn

Joined: Jan 06, 2008
Posts: 11
I want to send few parameters from js to a servlet.
How can i do this?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
Welcome to JavaRanch.

There are various ways this might be done, depending on whether the current page should be replaced by a different one,a nd whether the parameters are part of a link clicked by the user or part of an HTML form. Can you tell us a bit more about the circumstances?


Ping & DNS - updated with new look and Ping home screen widget
santu Naid
Greenhorn

Joined: Jan 06, 2008
Posts: 11
Actually its an jsp page,
In this page there are many hidden fields with ids, which are made visible by calling js functions, which are called on onclick.
My job is to make an array in which i have save the ids of these hidden fields and save in a session object,
so that when i come back to this page again, the hidden fields are in visible state.

So i want to send this array to the servlet
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

One way could be this -
You can set the values in hidden "input" fields which are in the same html form that is submitted. You can retrieve these values on the server using
request.getParameter("fieldName"); or request.getParameterValues("fieldName") and send them back to the page.
santu Naid
Greenhorn

Joined: Jan 06, 2008
Posts: 11
Thanks,
Actually i knew this method
but wanted an another way,
Any way thanks,
i just want to ask is there any way by which i can directly access a js variable in a servlet?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
is there any way by which i can directly access a js variable in a servlet?

Since JavaScript runs on the client, while servlets run on the server, you can't.
santu Naid
Greenhorn

Joined: Jan 06, 2008
Posts: 11
Ok thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing parameter from js to servlet
 
Similar Threads
javascript import
Applet vs JavaScript
Invoke java method from JavaScript (not applet!)
Calling .js file from Java
Sessions on a servlet