I am a rails dev and starting to learn Java. I'm interested in building a java web server and have it execute certain commands by url for instance:
http://localhost:8080/downloadFile?id=1000
Would tell the webserver to go download a file with the id of 1000 from another server.
Should I be using a framework like Play 2.0 or something?
Appreciate any help!
=============================================================================
For anyone looking for a simple solution:
https://github.com/perwendel/spark
Quick Example:
import static spark.Spark.*; import spark.*; public class HelloWorld { public static void main(String[] args) { get(new Route("/hello") { @Override public Object handle(Request request, Response response) { // Execute code here return "Hello World!"; } }); } }
If you want to use url parameters you can simply call request.queryParams("parameternamehere")
. So if I wanted to have that /hello
route use ?name=john
to get the name, I would need to call request.queryParams("name")
.
I was able to get this quickly running with IntelliJ, installed com.sparkjava:spark-core:1.0
via maven, and then just created a new java class under /src/main/java.