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 7440471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:51:27+00:00 2026-05-29T10:51:27+00:00

I am trying to pass a parameter from AJAX back to my JSP page.

  • 0

I am trying to pass a parameter from AJAX back to my JSP page. Here is my sample code:

JS File:

$(document).ready(function() { 
            $.ajax({
            type: "GET",
            url: "URL...",
            dataType: "xml",
            success: function(xml) {
                $(xml).find('Rowsets').each(function(){ 
                            var x = $(this).find('Auto_Id').text() // Assign data from Auto_Id into variable x
                    document.form.y.value = x; // Pass the parameter back to the JSP page
                    });
                }
    });
});

.JSP File:

<FORM name="form"><input name="y" value="" /></FORM> //value left blank for AJAX to auto-populate

The above code works – I am able to get the parameter x. However, is it possible to get the value of x into the following format on the same .JSP page?

<%= session.getAttribute("x") %>

Or, get the value of x and pass it into the java tags <%= %>?

The purpose of this is to grab the parameter from the XML (via AJAX) on page load, pass a parameter back to my JSP page so that I can use it to dynamically create a URL (e.g. “http://xyz&Param=&#8221; + session.getAttribute(“x”) + “”). Note that the URL has to be defined in java tags <%= …. %> of the jsp page.

  • 1 1 Answer
  • 0 Views
  • 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-29T10:51:28+00:00Added an answer on May 29, 2026 at 10:51 am

    You can’t use Javascript variable in scriptlets. I hope you know that, JSPs are executed at server side and before making your AJAX call. You should do some tweaks in your code to achive this, construct the URL in JS. Like this,

    In JSP, You can have,

    <input type='hidden' value='<%=dynamicallyCreatedURL%>' id='dynamicallyCreatedURL'/>
    

    Read the above hidden element in Ajax Response callback to construct the URL. You can use constructed url in anywhere. Here I used as form action

    $(xml).find('Rowsets').each(function(){
        var x = $(this).find('Auto_Id').text() // Assign data from Auto_Id into variable
        document.form.y.value = x; // Pass the parameter back to the JSP page 
    
        //Here construct the URL and set as forma action
       var dynamicallyCreatedURL = document.getElementById('dynamicallyCreatedURL').value+'?param='+x; 
    document.form.action = dynamicallyCreatedURL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass parameter from python page to another through the URL,this parameter(key
I'm trying to pass parameter of short type to C++ unmanaged function imported from
I'm trying to pass a parameter from php into my javascript function inside html.
I'm trying to pass a parameter from a parent function to a child function
I'm trying to pass a null value for the first parameter in the code
I am trying to pass in a function as a parameter: GEvent.addListener(marker_1, click, populateMarkerWindow(0,
I am trying to pass the parameters from a .feature file (cucumber) to a
i'm trying to pass a parameter from a activity Main, to the tabs of
I am trying to pass the parameter constraint to PDO from an array i.e.
I'm trying to pass some values from one .aspx page to an handler (.ashx).

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.