简单的 Java 网络框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2125529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple Java web framework
提问by Gabriel
Is there any simple java web framework like sinatra (for ruby) or web.py (for python)?
有没有像 sinatra(用于 ruby)或 web.py(用于 python)这样的简单 Java Web 框架?
回答by danben
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.
我认为通过 Java 生成 Web 内容最简单的方法是编写一个 Servlet。就像 web.py 允许你定义一个GET
方法一样,你可以实现一个 Servlet 的doGet()
方法并将数据直接写回客户端。
Here is a linkto 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").
这是Servlets 教程的链接。您还需要知道如何打包和部署 Web 应用程序;为此,我通常会向人们指出Tomcat 手册(请参阅标题为“第一个 Web 应用程序”的部分)。
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.
编写和部署 Java Web 应用程序不会像在 Ruby 或 Python 中那样快,但 Java 并不以其简洁而著称。
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.
如果您不严格要求 Java,请查看Grails。它是一个基于 Groovy 构建的 Web 应用程序框架,Groovy 是一种类似于 Python 和 Ruby 的动态语言,可以编译到 JVM。
回答by Pascal Thivent
If you are only looking for a presentation framework in pureJava then, for me, Stripes1is the closest of the Java MVC frameworks to the RoR philosophy: simple, elegant, and requiring minimal configuration.
如果您只是在寻找纯Java的表示框架,那么对我来说, Stripes 1是最接近 RoR 哲学的 Java MVC 框架:简单、优雅且需要最少的配置。
1Stripes pioneered the Convention over Configurationapproach 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.
1Stripes 开创了Java Web 开发的约定优于配置方法。虽然其他一些框架已经采用了它的一些原则(比如 Spring MVC 或带有插件的 Struts2),但我仍然更喜欢 Stripes,因为它只做一件事,而且做得很好。
回答by Pascal Thivent
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, Restlethas a built in HTTP daemon that means you can run it as a stand alone web server.
我能找到的支持 Servlet 的最小的 Java“可用”Web 服务器是Miniature JWS。老实说,没有理由运行不支持 Servlet 的 Java Web 服务器。如果你想做 REST,Restlet有一个内置的 HTTP 守护进程,这意味着你可以将它作为一个独立的 web 服务器运行。
回答by Johannes
回答by helpermethod
回答by Hendy Irawan
Java EE 6 Servers like GlassFishbundles it by default.
像GlassFish这样的 Java EE 6 服务器默认捆绑它。
If you use Tomcat, you can use Jersey, Apache CXF, or Restletimplementations.
如果您使用 Tomcat,则可以使用Jersey、Apache CXF或Restlet实现。
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...
使用 JAX-RS 注释,Web 开发感觉就像 Sinatra 或 Merb。顺便说一句,您不必使用 Java 作为语言,您可以使用 Scala、Groovy、JRuby ......
回答by Alex
HybridJava frameworkis 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.
HybridJava 框架非常简单。当然,它像 Servlet API 之上的 API 一样构建,但处理页面和组件而不是请求和响应。换句话说,它是真正的 MVC。
回答by Yossarian
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.
使用 SerfJ 是开发 Java REST Web 应用程序的最简单方法。它帮助您在优雅的 MVC 架构上开发您的应用程序,使约定比配置更重要,因此例如,您不必拥有配置文件或注释来指定哪个视图为控制器的方法提供服务。然而,SerfJ 是一个非常灵活的库,因此如果您想跳过这些约定,您可以根据需要配置应用程序的行为。
该框架试图满足 JSR 311 规范,但它并没有遵循其中的每一点,因为目的是拥有一个非常直观的库,而规范的某些方面超出了 SerfJ 的范围。
SerfJ 是开源的,在 Apache 许可下发布,版本 2.0。