Results 1 to 4 of 4

Thread: Passing Javascript variable value into JSP scriptlet

  1. #1
    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.

  2. #2
    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");

  3. #3
    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.

  4. #4
    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.

Similar Threads

  1. How to Pass a Javascript variable to a PHP script
    By leshaspar in forum Software Development
    Replies: 4
    Last Post: 24-11-2010, 10:48 AM
  2. Passing XSL value to javascript function
    By Steadfast in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:51 PM
  3. How to setup a JavaScript Object Notation variable?
    By hatred in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 02:25 AM
  4. Replies: 5
    Last Post: 25-01-2010, 04:59 PM
  5. javascript dynamic variable name
    By Lauren Bacall in forum Software Development
    Replies: 3
    Last Post: 17-06-2009, 04:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,838,474.84752 seconds with 17 queries