Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 811011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:58:32+00:00 2026-05-15T00:58:32+00:00

How can I access an JavaScript variable from within an JSP page ?

  • 0

How can I access an JavaScript variable from within an JSP page ?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:58:33+00:00Added an answer on May 15, 2026 at 12:58 am

    My guess is that you’re probably running Javascript on the client (in the browser), and Java in your JSP pages on the server. You can’t access a client-side variable on the server. You can send a client-side variable’s value from the client to the server for server-side processing. You’d probably do that via an Ajax call, or just by submitting a form.

    Edit For example, this Javascript code sends the value of the foo variable to the server side page ‘test.jsp’ using the field name “foofield” (slightly different name to be clear). This uses Prototype, but jQuery, Closure, and all the other libs can do much the same thing, just with slightly different syntax:

    Server-side Java (in the JSP) — this is just like getting fields from a form that’s been submitted:

    String foo;
    
    foo = request.getParameter("foofield");
    

    Client-side Javascript (using Prototype’s Ajax.Request):

    // Our client-side `foo` variable
    var foo = "Hi there";
    
    // Send it to the server via Ajax (Prototype version)
    new Ajax.Request('test.jsp', {
        parameters: {foofield: foo},
        onSuccess: handleSuccess,    // Function to call on success; not shown
        onFailure: handleFailure     // Function to call on failure; not shown
    });
    

    If you prefer jQuery for the client-side, here’s that Prototype code rewritten for jQuery’s ajax function:

    // Our client-side `foo` variable
    var foo = "Hi there";
    
    // Send it to the server via Ajax (jQuery version)
    $.ajax({
        url: 'test.jsp',
        data: {foofield: foo},
        success: handleSuccess,  // Function to call on success; not shown
        error: handleFailure     // Function to call on failure; not shown
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I read/access a JSP variable from JavaScript?
I want to, from JavaScript, access as a variable the file that is loaded
How can I access a JSON array from a PHP variable in an external
Possible Duplicate: How can I access local scope dynamically in javascript? Hi all. We
<form name=myForm> <input type=text name=f['cart']]['product_name']/> </form> How can I access textfield's value using javascript?
Why I can access Session object in Page_Load method in instance of System.Web.UI.Page, but
I have a class within Javascript with a variable assigned in the constructor. I
As long as I am calling my javascript code from within the jquery $().ready();
how can i access a variable that was intialsed in a function, but the
How can I define a global javascript variable in this situation? I want the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.