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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:25:30+00:00 2026-05-13T14:25:30+00:00

I have session key that is a JavaScript variable which I got from a

  • 0

I have session key that is a JavaScript variable which I got from a REST API call. I need to call my Java code in a servlet and pass that key as a parameter. What JavaScript function can I use to do that?

  • 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-13T14:25:31+00:00Added an answer on May 13, 2026 at 2:25 pm

    Several ways:

    1. Use window.location to fire a GET request. Caveat is that it”s synchronous (so the client will see the current page being changed).

      window.location = "http://example.com/servlet?key=" + encodeURIComponent(key);
      

      Note the importance of built-in encodeURIComponent() function to encode the request parameters before passing it.

    2. Use form.submit() to fire a GET or POST request. The caveat is also that it”s synchronous.

      document.formname.key.value = key;
      document.formname.submit();
      

      With

      <form name="formname" action="servlet" method="post">
          <input type="hidden" name="key">
      </form>
      

      Alternatively you can also only set the hidden field of an existing form and just wait until the user submits it.

    3. Use XMLHttpRequest#send() to fire an asynchronous request in the background (also known as Ajax). Below example will invoke servlet”s doGet().

      var xhr = new XMLHttpRequest();
      xhr.open("GET", "http://example.com/servlet?key=" + encodeURIComponent(key));
      xhr.send(null);
      

      Below example will invoke servlet”s doPost().

      var xhr = new XMLHttpRequest();
      xhr.open("POST", "http://example.com/servlet");
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      xhr.send("key=" + encodeURIComponent(key));
      
    4. Use jQuery to send a crossbrowser compatible Ajax request (above xhr code works in real browsers only, for MSIE compatibility, you”ll need to add some clutter 😉 ).

      $.get("http://example.com/servlet", { "key": key });
      

      $.post("http://example.com/servlet", { "key": key });
      

      Note that jQuery already transparently encodes the request parameters all by itself, so you don”t need encodeURIComponent() here.

    Either way, the key will be just available by request.getParameter("key") in the servlet.

    See also:

    • How to use Servlets and Ajax?
    • Access Java / Servlet / JSP / JSTL / EL variables in JavaScript
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The piki object will be autodeleted when the current scope… May 16, 2026 at 5:26 pm
  • Editorial Team
    Editorial Team added an answer This is the default style by the browser, not the… May 16, 2026 at 5:26 pm
  • Editorial Team
    Editorial Team added an answer JavaScript in web browsers is run in a single thread.… May 16, 2026 at 5:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two sessions in PHP: $_SESSION[session][key] = md5 ($token . $userAgent . $ip);
I have declared a structure that look like typedef struct { char* key; char*
I have a Java application with server and Swing client. Now I need to
I've got an asp.net application which seems to forget that a user is logged
I can persist an object into the DB from Java as such: Table Person:
I have a LAMP setup and I just want to be able to protect
I have a Python Facebook project hosted on Google App Engine and use the
The Situation I have a very compressed time schedule to write a simple (basically
I am designing a web site in which users solve puzzles as quickly as
I have two exactly the same web sites hosted in two different machines under

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.