[JAVA] How to get parameters in Spark

There are several ways to pass data when retrieving data from a client.

Request parameters

How to specify a variable after the URL after?

You can get it with request.queryParams

POST data

How to set a variable in the request body.

You can get it with request.queryParams.

If the same variable name is specified in the request parameter, the value will be overwritten and cannot be obtained.

Path parameter

Spark allows you to get part of the URL as a variable.

You can get it with request.params.


This is a sample of acquisition. How to receive the value when hitting this URL is

curl -X POST -d "postparam=hellopost" http://localhost:4567/hellopath/?urlparam=hellourl

 The acquisition method is as follows.

#### **`python`**

public static void main(String[] args) {

  post("/:pathparam/", (request, response) -> {
    System.out.println(request.param("pathparam")); // =>hello path is displayed
    System.out.println(request.queryParams("urlparam")); // =>hellourl is displayed
    System.out.println(request.queryParams("postparam")); // =>hellopost is displayed

    return null;


Recommended Posts

How to get parameters in Spark
How to get the date in java
How to get keycloak credentials in interceptor class
How to get Class from Element in Java
How to get information about associated tables in many-to-many tables
Where to get lost in specifications with Spark routing
[Rails] How to get the contents of strong parameters
How to get the class name / method name running in Java
How to use Lombok in Spring
How to find May'n in XPath
How to use Java HttpClient (Get)
How to hide scrollbars in WebView
How to get started with slim
How to iterate infinitely in Ruby
How to run Ant in Gradle
How to master programming in 3 months
How to learn JAVA in 7 days
How to get values in real time with TextWatcher (Android)
How to install Bootstrap in Ruby
How to use InjectorHolder in OpenAM
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to get along with Rails
How to set Lombok in Eclipse
[Rails5] japanMap link How to write parameters in js.erb file
How to concatenate strings in java
How to install Swiper in Rails
How to get the id of PRIMAY KEY auto_incremented in MyBatis
How to get boolean value with jQuery in rails simple form
How to get and add data from Firebase Firestore in Ruby
How to get the length of an audio file in java
How to get JDK 11 on your mac in a comfortable way
[swift5] How to specify color in hexadecimal
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to use custom helpers in rails
How to reflect seeds.rb in production environment
How to use named volume in docker-compose.yml
How to filter JUnit Test in Gradle
How to insert a video in Rails
How to include Spring Tool in Eclipse 4.6.3?
[Note] How to get started with Rspec
How to add jar file in ScalaIDE
How to do base conversion in Java
[Swift] How to fix Label in UIPickerView
How to have params in link_to method
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How to fix system date in JUnit
[Java] How to get the current directory
How to implement coding conventions in Java
How to embed Janus Graph in Java
[rails] How to configure routing in resources
How to map tsrange type in Hibernate
How to implement ranking functionality in Rails
How to use environment variables in RubyOnRails
How to implement asynchronous processing in Outsystems
How to publish a library in jCenter