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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:59:32+00:00 2026-05-31T22:59:32+00:00

Here is my Ajax code: var myJSONObject = {bindings: [ {ircEvent: PRIVMSG, method: newURI,

  • 0

Here is my Ajax code:

    var myJSONObject = {"bindings": [
                                     {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}]
                             };
    $.ajax({
        url : "ships",
        data : myJSONObject,
        success : function(data){
            GLOBAL.player.startShooting(data);
        },
        error : function(data) {
            console.log("error:", data);
        },
        dataType : "json",
        timeout : 30000,
        type : "post"
    });

And here is my Java Servlet code:

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    System.out.println("im in PSOT");
    System.out.println(request.getParameter("myJSONObject"));

    StringBuilder sb = new StringBuilder();
    BufferedReader br = request.getReader();
    String str;
    while( (str = br.readLine()) != null ){
        sb.append(str);
    }   
    System.out.println(sb.toString());
    response.setContentType("application/json");
    response.getWriter().write("{\"key\":\"hello\",\"key2\":\"world\"}");
}

The Java servlet returns my Hello World object, but i CANNOT read data in Java Servlet
The console prints out the following:

im in PSOT
null

The last line is an empty string from last println.

I am using Tomcat 7

Can anyone please tell me what i am doing wrong and why i cannot read data in Java Servlet_

  • 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-31T22:59:33+00:00Added an answer on May 31, 2026 at 10:59 pm

    The parameter name is not myJSONObject. That’s the JS variable name. The parameter names are all the root keys which you have there in your JSON object. E.g.

    String bindings = request.getParameter("bindings");
    // ...
    

    You’d only need to manually parse it further. You could use Google Gson for this.

    As to why the Reader didn’t return anything, that’s because the request body can be read and parsed only once. Any getParameter() call will implicitly do that. So when you call getParameter() before getReader(), you won’t be able to read the request body by the Reader (the same applies for the other way round!). But you don’t need it anyway. Just use getParameter() with the proper parameter names.

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

Sidebar

Related Questions

Here is my ajaxForm code var qx = $('#XText').attr('value'); $.ajax({ type: post, url: qsubmit.php,
Here is the code :- var quiz; function startQuiz() { $.ajax({ url: 'get_quiz/', cache:
How to get array data from json in c#? Here is the ajax code
Here's the parseFunction Ajax: { ParseHTML: function(aHTMLString) { var html = document.implementation.createDocument(http://www.w3.org/1999/xhtml, html, null),
I have the following code: var src, flickrImages = []; $.ajax({ type: GET, url:
Here is my full JS code: var timeOutId; function ft(){ $.get(progress.txt, null, function(data){ if(data.substr(0,10)
I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
Here is the code I'm currently using: $.ajax({ success: function(){ $('.post_container').append('test <br />'); }
i'm trying wmd editor over ajax. here there is the bugged code wdm code
I am trying to submit a form with ajax. Here is my complete code

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.