JAX-RS @FormParam Example

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

Hello, previously we have seen @PathParam and @QueryParam examples in JAX-RS. This article will deal with JAX-RS @FormParam example

 

JAX-RS @FormParam Example:

Usually we have seen that we submit forms in html or jsp pages using POST methods. These call some servlet url or a jsf method from a managed bean. Now in case of web services, we willl invoke an endpoint from a POST method in form. Just like @PathParam and @QueryParam, we can retrieve values from a form. This JAX-RS @FormParam Example will show exactly how it is done. Please understand how to create a hello world web service in JAX-RS.

HelloWorldService.java

Now create a jsp in which we will create a form.

Form.jsp:

Points to note here:

  • action="rest/HelloWorld/sayHelloToUser" will call the webservice endpoint.
  • HelloWorld” will map to HelloWorldService class.
  • sayHelloToUser” will map to sayHelloToUser method.

Now simply deploy this jax-rs @FormParam example application in your favourite application server.You can refer hello world example.

After deploying jax-rs @FormParam example, Open your jsp page by hitting url http://localhost:8080/JAX-RS_examples/Form.jsp.

You will see the page as below

FormParam ExampleNow enter your name in text box and hit “say Hello” button. You will see that the url in address bar is changed to http://localhost:8080/JAX-RS_examples/rest/HelloWorld/sayHelloToUser

You will see the text as

Hello Prasad Kharkar

This means our JAX-RS @FormParam Example is succesfull.

 

 

 

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Leave a Reply

Your email address will not be published. Required fields are marked *