用于 Web 的 Java 开发

2022-01-16 00:00:00 frameworks java

我希望开始使用 Java 进行 Web 开发 - 我有一些基本的 Java 知识,所以这不是问题,但是在破译用于 Web 应用程序的各种技术时,我不知所措.

I'm looking to start developing for the web using Java - I have some basic Java knowledge, so that's not a problem, but I'm at a loss when it comes to deciphering the various technologies for use in web applications.

我有哪些选择?它们是如何工作的?是否有任何类似于 Django/Ruby on Rails 的框架可以用来简化事情?

What options are available to me? How do they work? Are there any frameworks similar to Django/Ruby on Rails which I could use to simplify things?

任何有助于理解可用内容的链接将不胜感激.

Any links which could help with understanding what's available would be much appreciated.

推荐答案

Java 框架有两种基本风格.一个称为动作"框架,另一个称为组件"框架.

Java frameworks come in two basic flavors. One is called the "Action" Framework, the other the "Component" Framework.

动作框架专门用于将 HTTP 请求映射到 Java 代码(动作),并将 HTTP 请求绑定到 Java 对象.Servlet 是 Action Framework 中最基本的,也是所有其他框架的基础.

Action frameworks specialize on mapping HTTP requests to Java code (actions), and binding HTTP Requests to Java objects. Servlets is the most basic of the Action Frameworks, and is the basic upon all of the others are built.

Struts 是最流行的 Action 框架,但我不能凭良心向任何人推荐它.Struts 2 和 Stripes 更现代,并且彼此非常相似.两者的配置都很简单,开箱即用,易于使用,提供了非常好的绑定功能.

Struts is the most popular Action framework, but I can't in good conscience recommend it to anyone. Struts 2 and Stripes are more modern, and very similar to each other. Both are light on the configuration and easy to use out of the box, providing very good binding functionality.

组件框架专注于 UI,并倾向于促进基于高级 UI 组件(按钮、列表框等)的更多事件驱动架构.这些框架倾向于将来自编码器的实际 HTTP 请求隐藏在几个层下.它们使开发更高级的 UI 变得更加容易..NET 是 Windows 的组件框架.在 Java 上,流行的组件框架是 JSF(一种标准)和 Wicket.

Component Frameworks focus on the UI and tend to promote a more event driven architecture based on high level UI components (buttons, list boxes, etc.). The frameworks tend to hide that actual HTTP request from the coder under several layers. They make developing the more advanced UIs much easier. .NET is a component framework for Windows. On Java, the popular component frameworks are JSF (a standard) and Wicket.

通常,如果您要创建网站".这更类似于呈现信息(如博客或社区网站),Action 框架工作得更好.这些网站往往更简单,经常被添加书签,需要漂亮的 URL"等.这通常使用 Action 框架更容易做到.

As a rule, if you're creating a "web site". that is something more akin to presenting information (like a blog, or a community site), the Action frameworks work better. These sites tend to be simpler, get bookmarked often, require "pretty URLs" etc. This is generally easier to do with an Action framework.

组件框架更适合诸如具有大量 UI 元素和复杂工作流程的后台应用程序.您会发现,尤其是使用工具,这些风格的应用程序将使用组件框架更快地组合在一起.但是组件框架有更复杂的请求工作流程,有时依赖隐藏状态、大量的 POST 操作等.很多都有可怕"的 URL,有时会创建难以添加书签的页面.

Component frameworks are much better for things like back office applications with lots of UI elements and complicated workflows. You'll find, particularly with tooling, that these style of apps will go together faster using a component framework. But component frameworks have more complicated request workflow, sometimes relying on hidden state, lots of POST actions, etc. Many have "horrible" URLs, and sometimes create pages that are difficult to bookmark.

这两个框架都可以用于这两个任务,只是有些框架比其他框架更适合该任务.

Both frameworks can be used for both tasks, just some are more suited to the task than others.

这些框架都没有直接解决持久性问题,但许多框架具有与 JPA/EJB3 或 Hibernate 紧密配合的扩展模块或惯用语.

None of these frameworks directly address persistence, but many have extension modules or idioms that work tightly with JPA/EJB3 or Hibernate.

相关文章