Spark Java file upload example

In this post we will see how to upload a multipart file using Spark Java. We will have a HTML frontend where user will select a file from his/her system. Then pressing the “Upload” button the file will be posted as multipart data to server. In the server side, the multipart file will be fetched and saved to a defined directory. Using Spark Java, we can achieve this by writing just few lines of code.

Spark Java AJAX post example using JQuery

This post is very similar with the Spark Java example with JQuery Ajax except here we would use POST method for the Ajax call. Like the other example, we would get input of two numbers from the web page UI, make a ajax POST call to server with those numbers, the numbers get added at the server and returned result and finally display the result to web page UI without refreshing the page.

Spark Java example with AJAX JQuery

Spark is a relatively new, simple and lightweight framework written in Java which helps developers to rapidly create web services in minimal effort. It comes with embedded Jetty web server which hosts the web services. The syntax of declaring web services are very simple, quite similar with Node.js, which makes Node.js developers learn SparkJava quickly. Spark framework only works on Java 8 as it is built on Java 8’s Lambda philosophy.