Home  >  Web Services

@QueryParam Example in REST Web Service

By Arvind Rai, May 21, 2014
On this page we will provide @QueryParam Example in REST Web Service using RESTEasy. In JAXRS, to consume values from query string we use @QueryParam. It is applied in method argument level. For more than one keys in query string, we need to use more than one @QueryParam. Suppose query string is like

?name=Ram&collegeName=UP College

Then we can use @QueryParam as below

(@QueryParam("name") String name,@QueryParam("collegeName") String collegeName)

To access value of query string, use name and collegeName variable. Find the example to use @QueryParam
package com.concretepage.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

public class StudentService {
	public Student getStudentDetails(@QueryParam("name") String name,
			@QueryParam("collegeName") String collegeName) {
		Student student = new Student();
		return student;
Method will return JSON response for the @QueryParam input. Use the URL as below.

http://localhost:8080/RestWB-1/restwb/data?name=Ram&collegeName=UP College

Find the Student class used in above web service.
package com.concretepage.rest;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "student")
public class Student {
	private String name;
	private String collegeName;
	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;
	public String getCollegeName() {
		return collegeName;
	public void setCollegeName(String collegeName) {
		this.collegeName = collegeName;
Find the output.
@QueryParam Example in REST Web Service

Download Complete Source Code


©2022 concretepage.com | Privacy Policy | Contact Us