Nikos Maravitsas

About Nikos Maravitsas

Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. Currently, his main interests are system’s security, parallel systems, artificial intelligence, operating systems, system programming, telecommunications, web applications, human – machine interaction and mobile development.

JAX-RS @FormParam Example

In this example we are going to see how to parse parameters submited by a form in a JAX-RS REST Service using @FormParam annotation.

In this example we are not going to focus on how to create JAX-RS application from top to bottom. So make sure you read carefully Jersey Hello World Example and RESTEasy Hello World Example, and pay attention to the sections concerning the creation of the project with Eclipse IDE as well as the deployment of the project in Tomcat.

The code of this tutorial is going to be based on Jersey Hello World Example. You can download the Eclipse project of this tutorial here :

1. Project structure

Let’s remind ourselves the structure of the project we are working on:


At this point you can also take a look at the web.xml file to see how the project is configured:


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xsi:schemaLocation="" id="WebApp_ID" version="3.0">
  <display-name>Restful Web Application</display-name>



As you can see our servlet is mapped to /rest/ URI pattern. So the basic structure of the URIs to reach the REST Service will have the form :


So let’s see how to use @FormParam annotation.

2. Create a new HTML File

This is of course to host a simple HTML form to demonstrate the use of @FormParam annotation. Go to the Package Explorer, Right Click on the project -> New -> HTML File. The new file will be created in the WebContent folder.


So this would be the final project structure:


Now open form.html file and paste the following code:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Form Page</title>
<h1>Submit the following form</h1>

	<form action="rest/members/info" method="post">
			First Name : <input type="text" name="fname" />
			Last Name : <input type="text" name="lname" />
		<input type="submit" value="Submit" />

3. REST Servive

Open and paste the following code:



public class HelloWorldREST {

	public Response responseMsg(@FormParam("fname") String fname,	@FormParam("lname") String lname ) {

		String output = "This all the info about "+fname +" "+lname;
		return Response.status(200).entity(output).build(); 


So as you can see we are going to parse two parameters submited from the above form. Tha parameter naming is obvious.

4. Run the example

After deploying your Application (I used Tomcat for this), open your browser and go to:



You will see the following form. After typing the “First Name” and “Last Name”, hit “Submit” :


After submiting the form:

rest-service responce

5. Using MultivaluedMap<String, String>

You can use MultivaluedMap<String, String> to represent all form data. You will find it particularly useful when you have a form with a lot of input variables. Let’s see how:



public class HelloWorldREST {

	public Response responseMsg(MultivaluedMap<String, String> parameter1) {

		String output = " Form parameters :\n";
		for (String key : parameter1.keySet()) {
			output += key + " : " + parameter1.getFirst(key) +"\n";


		return Response.status(200).entity(output).build();

Open your browser and go to:



You will see the following form. After typing the “First Name” and “Last Name”, hit “Submit” :


After submitting the form:


Download Eclipse Project

This was an example on JAX-RS @FormParam annotation. Download the Eclipse Project of this example:

Related Whitepaper:

Java Essential Training

Author David Gassner explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more!

The course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts. Exercise files are included with the course.

Get it Now!  

Examples Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below: