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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:27:46+00:00 2026-06-14T04:27:46+00:00

I have a REST Server in Java JAX-RS and an HTML page. I want

  • 0

I have a REST Server in Java JAX-RS and an HTML page.

I want to send a JSON array, a username, and an accountID from the HTML page through an xmlhttp POST request by making all of them a single big String so I can use the xmthttp.send() method.

The HTML sending code is:

function sendData() {   
    var req = createRequest();
    var postUrl = "rest/hello/treeData";

    var dsdata = $("#treeview").data("kendoTreeView").dataSource.data();
    var accID = "onthespot";
    var username = "alex";

    req.open("post", postUrl, true);
    req.setRequestHeader("Content-type","text/plain");

    req.send("data=" + JSON.stringify(dsdata) + "&username=" + username + "&accID=" + accID);

    req.onreadystatechange = function() {
        if (req.readyState != 4) {
            return;
        }
        if (req.status != 200) {
            alert("Error: " + req.status);
            return;
        }
        alert("Sent Data Status: " + req.responseText);
    }
}

And the Server JAX-RS code is:

@Path("/treeData")
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String storeTreeData(
        @QueryParam("data") String data,
        @QueryParam("username") String username,
        @QueryParam("accID") String accID) {

        System.out.println("Data= " + data + "\nAccID= " + accID + "\nUsername= " + username);

        return "Done";
}

The problem is that all the variables are printed as null..
the storeTreeData function should find the data , username , accID variables through @QueryParam and store them isn’t that right?

Anyone know what’s the problem here?

PS:The xmlhttp request is initiallized correctly and the connection is made but the parameters are not passed on the server.

  • 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-06-14T04:27:48+00:00Added an answer on June 14, 2026 at 4:27 am

    What you try to do:

    @QueryParam is used to get parameters from the query of the request:

    http://example.com/some/path?id=foo&name=bar
    

    In this example id and name can be accessed as @QueryParam.

    But you are sending the parameters in the body of your request.

    What you should do:

    To get the parameters from the body, you should use @FormParam together with application/x-www-form-urlencoded:

    @Path("/treeData")
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.TEXT_PLAIN)
    public Response storeTreeData(
            @FormParam("data") String data,
            @FormParam("username") String username,
            @FormParam("accID") String accID) {
    
        // Build a text/plain response from the @FormParams.
        StringBuilder sb = new StringBuilder();
        sb.append("data=").append(data)
          .append("; username=").append(username)
          .append("; accId=").append(accID);
    
        // Return 200 OK with text/plain response body.
        return Response.ok(sb.toString()).build();
    }
    

    Edit:

    You should also use

    req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    

    in your JavaScript code.

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

Sidebar

Related Questions

I have to send .csv file to remote server through REST in rails. I
I have a JAX-RS based ( RESTEasy ) REST server that uses Java annotations
I have developed a REST application server based on RESTEasy (JAX-RS). I have a
I have several hand-written Java classes in a REST Server that uses JAXB to
I have a problem with sending ArrayList from server to my client using JAX-rs.
I'm using eclipse and I have a java web service (rest jax-rs) I also
I have developed a REST based server in java for Android devices and Desktop
I'm working on a Java REST server serving an iPhone app. Now we have
I have a bugzilla server which i am trying to access through the rest
i have a server - client application that runs on java 1.3; i want

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.