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

  • SEARCH
  • Home
  • 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 4588348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:54:34+00:00 2026-05-21T21:54:34+00:00

I am using XMLHttpRequest to create a simple form submitand get session variable from

  • 0

I am using XMLHttpRequest to create a simple form submitand get session variable from the servlet. But nothing seems to work. Can somebody point out where am I going wrong?

Here is the Form

<form method="post" target="_self" action="/temp/Welcome.html">
    <table>
        <tr>
            <td>Email</td>
            <td><input type="text" id="email" name="email" value="a@a.com"></td>
        </tr>
        <tr>
            <td>Project ID</td>
            <td><input type="text" id="projectid" name="projectid" value="1111"></td>
        </tr>
        <tr>
            <td colspan="2" align="right"><input type="button" id="submitbutton" value="Submit" onclick="submitLogin()"></td>
        </tr>
    </table>
</form>

here is the submitLogin function

function submitLogin()
{
 var url_action="/temp/Login";
 var client; 
 var dataString;
 if (client.XMLHttpRequest){ // IE7+, Firefox, Chrome, Opera, Safari
     client=new XMLHttpRequest();
 } else {                    // IE6, IE5
     client=new ActiveXObject("Microsoft.XMLHTTP");
 }

 client.onreadystatechange=function(){
     alert(client.responseText);
     if(client.readyState==4&&client.status==200)
     {
         alert(client.responseText);
     }
     else
         alert("Error: return status code "+client.status+" "+client.statusText);
 };
 dataString="email="+document.getElementById("email").value;
 client.open("POST",url_action,true);
 client.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

 client.send(dataString);
}

and my post method in Login.java servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    response.setContentType("text/plain");

    paramMap=request.getParameterMap();
    if (paramMap == null)
        throw new ServletException(
          "getParameterMap returned null in: " + getClass().getName());

    iterator=paramMap.entrySet().iterator();
    //System.out.println(paramMap.size());
    String str="";

    while(iterator.hasNext())
    {
        Map.Entry me=(Map.Entry)iterator.next();
        String[] arr=(String[])me.getValue();
        emailId=arr[0];
        //System.out.println(me.getKey()+" > "+emailId);

    }
    rand=new Random();
    randomInt=rand.nextInt(1000000);
    emailId=randomInt+emailId;
    System.out.println(emailId);
    out.println(emailId);

    /*creates a new session if a session does not exist already*/
    session=request.getSession();
    session.setAttribute("uid", emailId);

    out.close();
}

None of the alerts and the System.out seems to show any response. please guide me. Thanks

Note: in IE 8 it shows xmlhttprequest is null or not an object, login.js at Line no: 9

  • 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-21T21:54:35+00:00Added an answer on May 21, 2026 at 9:54 pm

    Looks like you have a simple typo in your Java Script

    var client; 
    
    if (client.XMLHttpRequest){
        client=new XMLHttpRequest();
    } else {
        client=new ActiveXObject("Microsoft.XMLHTTP");
    }
    

    You are declaring some variable called client and asking it for it’s XMLHttpRequest member. You probably meant to use window.XMLHttpRequest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using XMLHttpRequest to create a simple form submit and pass 2 parameters.
I am trying to do a simple application using Ajax and servlet. But when
I'm doing some straight up asynchronous calls from javascript using the XMLHTTPRequest object. On
Hi I'm trying to create a simple registration form with ajax validation. I've got
I'm using the flickr api to create a simple gallery based on images pulled
I am using an XMLHttpRequest to fetch an image from a server (run locally
I'm trying to do an XMLHttpRequest from a local file (file://) using JQuery.ajax to
I have a form where I'm using Jquery to submit the form to create
I am using a simple live search script that displays the results from a
I have an XML object (loaded using XMLHTTPRequest 's responseXML ). I have modified

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.