JAX-RS @FormParam Web service example

In this tutorial we are going to see how to get HTML form parameters in java method using RESTful web service via URL using JAX-RS @FormParam. @FormParam used to bind HTML form parameters to java method

Create maven web application project and add Jersey dependency in pom.xml. Find Jersey 2.x maven dependency configuration below. If you are new to maven refer our maven tutorials

Jersey 2.x dependency in pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <name>RestTutorials Maven Webapp</name>
      <!-- JAX-RS -->
        <!-- Jersey 2.19 -->

Create form-param.jsp under webapp folder

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<form action="rest/tutorial/jtc" method="post">
Site : <input type="text" name="site"/>
Tutorials :<input type="text" name="tutorial"/>
Rank :<input type="text" name="rank"/>
<input type="submit" value="Submit"/>


package com.ehowtonow.webservice;

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

public class FormParamService {

 public Response getTutorial(@FormParam("site") String site, 
   @FormParam("tutorial") String tutorial, @FormParam("rank") String rank) {
  return Response
    .entity("Web Site : " + site + "  Tutorial : " + tutorial
      + " Rank : " + rank).build();


Configure Jersey 2.x Servlet dispatcher

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

	<display-name>Restful Webservice Example</display-name>


Now you can run the jsp  and access the service by submit the form

run jsp


call service by submit form using post method


Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. JAX-RS Get HTTP Headers using @Context
  2. JAX-RS Send List using QueryParam Annotation
  3. JAX-RS @QueryParam with @DefaultValue – Jersey
  4. Download image using JAX-RS RESTful Webservice
  5. Download Text file using JAX-RS RESTful Webservice
  6. JAX-RS @MatrixParam Restful Webservice
  7. Download Excel file using JAX-RS RESTful Webservice
  8. Restful Webservice HelloWorld Jersey 2.x Example
  9. Restful Webservice HelloWorld Example Jersey 1.x
  10. JAX-RS Get HTTP Headers using @HeaderParam
  11. JAX-RS @PATH for URI – Jersey
  12. JAX-RS QueryParam – Jersey
  13. File Upload using JAX-RS RESTful Webservice (Jersey 2.x)
  14. JAX-RS Web service to Consume JSON using Jersey 1.x
  15. JAX-RS to Produce JSON using Jackson – Jersey 1.x

Be the first to comment

Leave a Reply