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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:24:47+00:00 2026-05-26T06:24:47+00:00

I want to develop rest api.such as: http://localhost:8080/TestSomeWay/resources/test/create?meg=sadasd&name=sadasd and get params from urlparams exp.meg&name

  • 0

I want to develop rest api.such as:
http://localhost:8080/TestSomeWay/resources/test/create?meg=sadasd&name=sadasd
and get params from urlparams exp.”meg”&”name”
I am using jersey to develop a Restful post method
it dose not make it out
code:

@POST
@Path("/create")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
@Override
public String create( @FormParam("meg")String megString, @FormParam("name")String nameString) {
   TestUser testUser=new TestUser();
   testUser.setMeg(megString);
   testUser.setName(nameString);
   em.persist(testUser);
   em.flush();
   return testUser.getId().toString();

}
  • 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-26T06:24:48+00:00Added an answer on May 26, 2026 at 6:24 am

    You seem to be confused as to what you are trying to achieve, and that’s showing up as an incoherent API. Once you’ve gone wrong that way, it’s small wonder that things are going wrong!

    First off, you’ve got to figure out whether you’re using GET, PUT or POST, and in the latter two cases, what is the content type (or types) that you are consuming, as both PUT and POST are typically dealing with a document incoming. Moreover, if you’re doing anything that isn’t idempotent (i.e., so that it would be “the same” if you did it twice in a row as if once) then you should definitely be using POST; the classic example is paying for some goods, which you definitely don’t want to do twice, whereas setting your preferences can be idempotent. The final complication is that it is usually bad style to mix query parameters with a body; either the parameters are in the query part or they are in the body (or they are in the path, but in that case you’re dealing with different resources conceptually).

    If you’re just dealing with HTML forms, the two styles of method you’ll want will be like this:

    @GET
    @Path("/create")
    @Produces(MediaType.TEXT_PLAIN)
    public String createFromGet(
            @QueryParam("meg") String meg,
            @QueryParam("name") String name) {
        ...
        return theString;
    }
    
    @POST
    @Path("/create")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.TEXT_PLAIN)
    public Response createFromPost(
            @FormParam("meg") String meg,
            @FormParam("name") String name) {
        ...
        return Response.created(theNewUrl).entity(theString).build();
    }
    

    The first deals with a GET on a URL like /create?meg=foo&name=bar and the second deals with a POST to a URL like /create. However, given the name “create” I’d be tempted to go with just using the POST version and to not try to support encoding the parameters in the query part; creation is one of those things that tends to not be idempotent.

    Note that I have assumed that your creation is making a resource (that’s good RESTful programming!) so I adjusted to return the right kind of response; it’s a bit more involved than the usual, but is exactly the right thing.

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

Sidebar

Related Questions

I want to develop my own REST service, so I've created an IHttpHandler that
I am using Spring MVC and want to develop a website that uses REST
I'm trying to develop a simple REST API. I'm still trying to understand the
I want to develop a windows application. If I use native C++ and MFC
I want to develop Java apps, real quick, what IDE should I choose?
I want to develop simple Serverless LAN Chat program just for fun. How can
I want to develop a mobile web application using asp.net 3.5 that can be
I want to develop a very simple 2D game in Python. Pygame is the
I want to develop an iPhone application using the utility template, where the flip
I want to develop ASP.NET C# based MMOG (Massively multiplayer online game). I would

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.