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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:16:20+00:00 2026-06-18T02:16:20+00:00

I want to create a REST Jersey Web-Service accepting JSON string as input parameter.

  • 0

I want to create a REST Jersey Web-Service accepting JSON string as input parameter.

Also I will use post requestand from webmethod I will return one JSON string.

How can I consume this in a HTML page using Ajax post request.
I want to know what all changes I need to make it on web method to accept JSON String.

 public class Hello {

      @POST
     public String sayPlainTextHello() {
      return "Hello Jersey";
      }
   }
  • 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-18T02:16:21+00:00Added an answer on June 18, 2026 at 2:16 am

    Need to break down your requests. First, you want to accept a JSON string. So on your method you need

    @Consumes(MediaType.APPLICATION_JSON)
    

    Next, you need to decide what you want your method to obtain. You can obtain a JSON string, as you suggest, in which case your method would look like this:

    @Consumes(MediaType.APPLICATION_JSON)
    public String sayPlainTextHello(final String input) {
    

    Or alternatively if your JSON string maps to a Java object you could take the object directly:

    @Consumes(MediaType.APPLICATION_JSON)
    public String sayPlainTextHello(final MyObject input) {
    

    You state that you want to return a JSON string. So you need:

    @Produces(MediaType.APPLICATION_JSON)
    

    And then you need to actually return a JSON string:

    return "{\"result\": \"Hello world\"}";
    

    So your full method looks something like this:

    @PATH("/hello")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public String sayPlainTextHello(final String input) {
      return "{\"result\": \"Hello world\"}";
    }
    

    Regarding using AJAX to send and receive, it would look something like this:

    var myData="{\"name\": \"John\"}";
    var request = $.ajax({
        url: "/hello",
        type: "post",
        data: myData
    });
    
    request.done(function (response, textStatus, jqXHR){
        console.log("Response from server: " + response);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Jersey to create a REST web service for a server component. The
I need to create a REST service with a POST method with 4 string
I simply want to create a fairly basic REST service, so that I can
I want to create a global option that when a REST call contains &format=json
I want to create two Rest methods that vary based on the query string
I want to create pet project with Java REST backend and PHP web-frontend(my friend
In my Web service I use eclipse, java 1.5, spring. now I want to
I've been trying to create a Jersey REST Webservice. I want to receive and
We use Jersey/Jackson for our REST application. Incoming JSON strings get mapped to the
I want create a rest method(http put) that takes a list of string as

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.