Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-09-2009
Member
 
Join Date: Oct 2008
Posts: 101
Passing Javascript variable value into JSP scriptlet

A recordset is retrieved from mySQL by a scriptlet in one frame of a page. I want to pass the var num to a servlet. I am aware of how to retrieve a variable using String num = request.getParameter("var"); A jsp page is loaded into a second frame with parameters that describe the current member of the recordset. It uses these to display a form with the existing values for the record as defaults.
Reply With Quote
  #2  
Old 23-09-2009
Member
 
Join Date: Feb 2009
Posts: 72
Re: Passing Javascript variable value into JSP scriptlet

To get the value of the JavaScript variable, a request needs to be submitted to the servlet, passing the value as a request parameter. Whenever user clicks on submit button the value of hidden form field will be appended to the request as, That can happen on the URL, or as part of a form submission. Your_servlet_name?field=valueofyour javascript variable, You can receive this value in servlet for processing by using

String s = request.getParameter("field");
Reply With Quote
  #3  
Old 23-09-2009
Member
 
Join Date: Oct 2008
Posts: 68
Re: Passing Javascript variable value into JSP scriptlet

Normally, the result of servlet is an HTML page, which might contain JavaScript. I'm not sure what you are trying to achieve here, but if you want to send some values to the server from your JSP without reloading the page, So you can not copy contents of servlet variable to javascript variable directly like in following code

Code:
for(int i=0; i<strAlpha.length;i++)
{
     letterArray[i]=strAlpha[i];
}
Servlets are executed at server while javascript is executed at client browser.
Reply With Quote
  #4  
Old 23-09-2009
Member
 
Join Date: Oct 2008
Posts: 127
Re: Passing Javascript variable value into JSP scriptlet

variable needs to be passed to a servlet or jsp through a request to the server and then the servlet or jsp can place that variable into the session. You can copy the value of javascript variable in html hidden field by using a script in. And now in jsp you can send the value of this field to servlet, Basically the reason I want to do this is that I have a dynamic form that extends to add multiple inputs. I want to assign a unique id to each impairment as the form extends. Then the servlet requests the impairment name with the unique id so I can iterate over them and add them into the database.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Passing Javascript variable value into JSP scriptlet"
Thread Thread Starter Forum Replies Last Post
How to Pass a Javascript variable to a PHP script leshaspar Software Development 4 24-11-2010 10:48 AM
Passing XSL value to javascript function Steadfast Software Development 6 13-05-2010 11:51 PM
How to setup a JavaScript Object Notation variable? hatred Software Development 4 04-02-2010 02:25 AM
How to change a variable that is saved in an object structure in JavaScript? DANIEL 602 Software Development 5 25-01-2010 04:59 PM
javascript dynamic variable name Lauren Bacall Software Development 3 17-06-2009 04:20 PM


All times are GMT +5.5. The time now is 04:30 PM.