问题
Is there any simple java web framework like sinatra (for ruby) or web.py (for python)?
回答1:
If you want a strict Java framework Spark might be an alternative:
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
回答2:
Play. Haven't tried it myself but heard only good things about it and seems to be quite beginner-friendly.
回答3:
I think the simplest thing to do to generate web content via Java is to write a Servlet. Just like web.py allows you to define a GET
method, you can implement a Servlet's doGet()
method and write data directly back to the client.
Here is a link to the Servlets tutorial. You will also need to know how to package and deploy a web application; for that I usually point people to the Tomcat manual (see the section titled "First Web Application").
Writing and deploying a Java web application is not going to be as fast as in Ruby or Python, but Java isn't particularly known for its succinctness.
If you don't strictly require Java, check out Grails. It's a web application framework built on Groovy, which is a dynamic language similar to Python and Ruby that compiles to the JVM.
回答4:
JAX-RS.
Java EE 6 Servers like GlassFish bundles it by default.
If you use Tomcat, you can use Jersey, Apache CXF, or Restlet implementations.
Using JAX-RS annotations the web development feels like Sinatra or Merb. BTW you don't have to use Java as the language, you can use Scala, Groovy, JRuby...
回答5:
If you are only looking for a presentation framework in pure Java then, for me, Stripes1 is the closest of the Java MVC frameworks to the RoR philosophy: simple, elegant, and requiring minimal configuration.
1 Stripes pioneered the Convention over Configuration approach for Java web development. And while some other frameworks have adopted some of its principles (like Spring MVC or Struts2 with plugins), I still prefer Stripes because it does one thing, and does it well.
回答6:
It is possible to use Sinatra as is with JRuby
回答7:
look at this two as well: 1. activeweb and 2. dropwizard
回答8:
You might want to have a look at those 2 groovy projects:
https://github.com/webdevwilson/graffiti
https://github.com/bleedingwolf/Ratpack
Really light akin to Sinatra. Might be a bit on the bleeding edge though:-) Interesting and promising never the less.
回答9:
Check SerfJ : Simplest Ever Rest Framework for Java :
Using SerfJ is the easiest way of developing Java REST web applications. It helps you to develop your application over an elegant MVC arquitecture, giving more importance to convention than configuration, so for example, you will not have to have configuration files or annotations in order to specify which view serves a controller's method. However, SerfJ is very flexible library, so if you want to jump over those conventions, you can configure the behaviour of your applications as you like.
The framework tries to meet JSR 311 specification, but it doesn't follow every point of that, because the purpose is to have a very intuitive library, and some some aspects of the specification are out of the scope of SerfJ.
SerfJ is opensource and is released under the Apache License, Version 2.0.
回答10:
If you have to develop business or database applications OpenXava is a good option. OpenXava allows you to develop a complete AJAX web application writing just domain classes, with no code generation and producing an application ready for production. Little code, great result.
回答11:
The smallest "usable" web server for Java that support Servlets that I can find is Miniature JWS. And honestly there is no reason to run a Java web server that doesn't support Servlets. If you want to do REST, Restlet has a built in HTTP daemon that means you can run it as a stand alone web server.
回答12:
HybridJava framework is really simple. Of course, it builds like an API above Servlet API, but deals with page and component instead of request and response. In other words it is truly MVC.
回答13:
Step is a framework for Scala inspired by Sinatra.
回答14:
I can recommend Struts2 to you, because i like the plugin architecture and with the convention plugin it is simple and fast to develop.
来源:https://stackoverflow.com/questions/2125529/simple-java-web-framework