解释:Java 如何作为 Web 应用程序工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9687519/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:09:28  来源:igfitidea点击:

Explain: How does Java work as a web application?

javaweb-applications

提问by Logan Klenner

Ok, I know this is a vague question, and I expect a vague/basic answer.

好的,我知道这是一个模糊的问题,我希望得到一个模糊/基本的答案。

I am well versed with PHP driven MVC frameworks and how the process of serving pages works. I'm very interested in learning Java, and I figure the only way to learn it is to do it. However, after reading page after page after page, it gets more confusing as I read.

我精通 PHP 驱动的 MVC 框架以及页面服务过程的工作原理。我对学习 Java 非常感兴趣,我认为学习它的唯一方法就是去做。然而,在一页一页地阅读之后,当我阅读时,它变得更加混乱。

I'm running into GWT (front end), Hibernate (ORM connection?), Spring Architecture, Spring Roo (what is this?), JBoss (servelet), JPA (ORM), POJO (a style of using regular java objects with orm?), Maven?

我遇到了 GWT(前端)、Hibernate(ORM 连接?)、Spring Architecture、Spring Roo(这是什么?)、JBoss(servelet)、JPA(ORM)、POJO(一种使用常规 java 对象的风格) orm?),Maven?

My basic question is how do all of these fit together? I like the idea of using a framework, because it's worked well in the past with PHP. How do I use this functionality with java? Suppose I wanted to build a web application with a relational data store. How does java authenticate, initate a session, and serve pages with dynamic content? What is the process?

我的基本问题是如何将所有这些组合在一起?我喜欢使用框架的想法,因为它过去在 PHP 中运行良好。如何在 Java 中使用此功能?假设我想构建一个带有关系数据存储的 Web 应用程序。java 如何进行身份验证、启动会话以及为具有动态内容的页面提供服务?过程是怎样的?

When responding, please don't say "stick with what you know," (as I've seen on other pages) because I'm very interested about java and I'm trying to learn.

回复时,请不要说“坚持你所知道的”(正如我在其他页面上看到的那样),因为我对 Java 非常感兴趣并且我正在努力学习。

回答by dldnh

One of the nice things about GWT is that you'll right your client code in Java, with all of its benefits and if you have server code, that could also be in Java as well, and you could share some of the source code, even if the front-end ends up running as JavaScript.

GWT 的好处之一是你可以用 Java 修正你的客户端代码,以及它的所有好处,如果你有服务器代码,也可以用 Java,你可以分享一些源代码,即使前端最终作为 JavaScript 运行。

回答by Vijay Agrawal

I totally hear you - too many acronymns have propped up as Java EE has evolved.

我完全听到您的声音 - 随着 Java EE 的发展,支持了太多的首字母缩略词。

I will try to put an explanation Java is the language Java EE (Java Enterprise Edition) is the general term used to encapsulate all Java technologies that help create an enterprise/web application with Java

我将尝试解释 Java 是语言 Java EE(Java 企业版)是用于封装所有有助于使用 Java 创建企业/Web 应用程序的 Java 技术的通用术语

So a typical web application with Java looks like follows:

因此,一个典型的 Java 网络应用程序如下所示:

Front End

前端

  • Use JSP or JSF for server side processing and rendering (JSP and JSF offer ability to define your UI using HTML and server side tags that bind easily with your Java Beans) However they do tend to mix UI with backend if not implemented correctly
  • you can also use plain HTML and any client side toolkits for rendering (such as jquery, dojo, extjs or flex) and fetch your data from the Java EE server.
  • you can even mix the two (use a client side framework in a JSP to achieve best of both) or use a toolkit like GWT that offers client side richness with javascript with Java APIs and ease of accessing your java beans
  • 使用 JSP 或 JSF 进行服务器端处理和渲染(JSP 和 JSF 提供使用 HTML 和服务器端标签定义 UI 的能力,这些标签可以轻松与 Java Bean 绑定)但是,如果未正确实现,它们确实倾向于将 UI 与后端混合
  • 您还可以使用纯 HTML 和任何客户端工具包进行渲染(例如 jquery、dojo、extjs 或 flex)并从 Java EE 服务器获取数据。
  • 您甚至可以将两者混合使用(在 JSP 中使用客户端框架来实现两者的最佳效果)或使用 GWT 之类的工具包,该工具包通过带有 Java API 的 javascript 提供客户端丰富性并易于访问您的 java bean

Middle tier

中层

  • Java Servlets offer the base for all server side processing with Java EE (Servlets offer session persistence, HTTP request processing, response processing) and typically offload the business processing to a model bean - which could be a POJO or spring bean. Servlets are Java programs you write and are executed in what is called a Java EE container. Popular containers are tomcat, IBM websphere, BEA Weblogic
  • Java Servlet 为使用 Java EE 的所有服务器端处理提供基础(Servlet 提供会话持久性、HTTP 请求处理、响应处理),并且通常将业务处理卸载到模型 bean - 它可以是 POJO 或 spring bean。Servlet 是您编写并在所谓的 Java EE 容器中执行的 Java 程序。流行的容器有 tomcat、IBM websphere、BEA Weblogic

To help implement a good MVC architecture, there are several frameworks and tools provided on top of Servlets:

为了帮助实现一个好的 MVC 架构,在 Servlet 之上提供了几个框架和工具:

  • Struts2 and Spring MVC are examples of such frameworks
  • To make it easy to implement web services, Restlet/Jersey help with REST based web services, JAX-WS/APache Axis help with SOAP based web services
  • Struts2 和 Spring MVC 是此类框架的示例
  • 为了便于实现 Web 服务,Restlet/Jersey 帮助基于 REST 的 Web 服务,JAX-WS/APache Axis 帮助基于 SOAP 的 Web 服务

Integration with backend database/persistent store

与后端数据库/持久存储集成

  • You could use JDBC in your POJO or other model bean to access the DB using Java.
  • Or alternately use one of the frameworks such as Hibernate to make it easy to interface with the DB backend
  • 您可以在 POJO 或其他模型 bean 中使用 JDBC 来使用 Java 访问数据库。
  • 或者交替使用 Hibernate 等框架之一,以方便与 DB 后端交互

Sun's petstore application is a good place to start to learn how the pieces fit together

Sun 的 petstore 应用程序是了解各个部分如何组合在一起的好地方

http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eedocs-419425.html#7522-petstore-1.1.2-oth-JPR

http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eedocs-419425.html#7522-petstore-1.1.2-oth-JPR

Build and Deployment

构建和部署

  • Ant and Maven are tools used to build your app and manage dependencies
  • the application gets packaged as a WAR or EAR file and can be dropped into any Java EE container to deploy it. Once it is deployed, it can be accessed using a URL
  • Tools like Eclipse, Netbeans, Oracle JDeveloper offer integrated IDEs to help with local deployment and testing
  • Ant 和 Maven 是用于构建应用程序和管理依赖项的工具
  • 应用程序被打包为 WAR 或 EAR 文件,并且可以放入任何 Java EE 容器中进行部署。部署后,可以使用 URL 访问它
  • Eclipse、Netbeans、Oracle JDeveloper 等工具提供集成 IDE 以帮助进行本地部署和测试

The good part with Java EE is that you can pick and choose the components you want to use to build your webapp.

Java EE 的好处是您可以挑选要用于构建 Web 应用程序的组件。

回答by cdeszaq

The problem Java has is that it's fairly old and there are TONS of frameworks and packages that do similar things as other packages. At the very core, however, is the Servlet, that specifies how Java behaves as a server over the HTTP protocol.

Java 的问题在于它相当古老,并且有大量的框架和包与其他包做类似的事情。然而,最核心的是Servlet,它指定了 Java 作为服务器如何通过 HTTP 协议运行。

With that basic building block, there are lots of web frameworks like Struts, and Spring MVC that build up layers of functionality by using lots of good OO development patterns, like Fiters, Delegates, Factories, MVC, etc., to allow the developer to put together an application that takes web requests as input and returns a web response as output.

有了这个基本的构建块,有很多 web 框架,比如 Struts 和 Spring MVC,它们通过使用很多好的 OO 开发模式(比如 Fiters、Delegates、Factories、MVC 等)来构建功能层,以允许开发人员将 Web 请求作为输入并返回 Web 响应作为输出的应用程序放在一起。

Those frameworks often build on other frameworks or packages to give application developers more capabilities at different layers of the application. This includes things like ORMs (like Hibernate) to talk to relational databases, or view compositing frameworks like Tiles or Velocity to help put together an HTML page as part of the response.

这些框架通常建立在其他框架或包之上,以在应用程序的不同层为应用程序开发人员提供更多功能。这包括诸如 ORM(如 Hibernate)之类的东西,用于与关系数据库对话,或者查看诸如 Tiles 或 Velocity 之类的合成框架,以帮助将 HTML 页面组合在一起作为响应的一部分。

There are lots of other acronyms and tools and layers that get built up around web frameworks, but essentially they are all just programming tools that have useful functionality pre-built and just need to be used.

围绕 Web 框架构建了许多其他首字母缩略词、工具和层,但本质上它们都只是具有预先构建的有用功能并且只需要使用的编程工具。

If you are looking for a more packaged web application development framework that is more cohesive and doesn't make you feel quite as lost, you may want to take a look at Grails. It is in Groovy, but it is very close to Java in terms of the language and actually builds on top of lots of the other tools you have heard of.

如果您正在寻找一个更具内聚力且不会让您感到迷茫的打包的 Web 应用程序开发框架,您可能需要看看Grails。它在Groovy 中,但它在语言方面非常接近 Java,并且实际上构建在您听说过的许多其他工具之上。

Grails itself builds on the Springand Spring MVCframeworks, as well as Hibernate, so it's using the same technologies as other more pure Java frameworks, but it abstracts the ugly details away so you don't have to worry about them unless you want to. You can then bundle in additional functionality, like authentication / security, through plugins. If you are well versed in PHP-based MVC frameworks and how they work from an architecture standpoint, you will feel right at home in a similar MVC environment like Grails or Spring MVC. The Grails User Guideis a great place to start, and the rest of the documentationis good too.

Grails 本身构建在SpringSpring MVC框架以及Hibernate之上,因此它使用与其他更纯的 Java 框架相同的技术,但它抽象了丑陋的细节,因此您不必担心它们,除非您想. 然后,您可以通过插件捆绑附加功能,例如身份验证/安全性。如果您精通基于 PHP 的 MVC 框架以及它们如何从架构的角度工作,那么您会在类似 Grails 或 Spring MVC 的 MVC 环境中感到宾至如归。Grails用户指南是一个很好的起点,其余的文档也很好。

If you are new to the Java language, I would strongly suggest doing a few small applications (not web apps, just simple ones) to learn the language and get familiar with how things work. Java is very different from PHP, since PHP bundles in a lot of the base functionality into the language whereas Java has a fairly sparse language with much of the commonly used functionality coming from libraries.

如果您不熟悉 Java 语言,我强烈建议您做一些小型应用程序(不是 Web 应用程序,只是简单的应用程序)来学习该语言并熟悉它的工作原理。Java 与 PHP 非常不同,因为 PHP 将许多基本功能捆绑到语言中,而 Java 是一种相当稀疏的语言,其中大部分常用功能来自库。

Once you have a good grasp of the Java language, I would jump right to the Grails framework and I would skip all of the nitty-gritty details of servlets and ORMs and Hibernate, etc. at first because you don't need to know it all and there is so much there that it can get in the way of actually understanding things.

一旦你很好地掌握了 Java 语言,我会直接跳到 Grails 框架,我会首先跳过 servlet、ORM 和 Hibernate 等的所有细节,因为你不需要知道它一切都在那里,它会妨碍实际理解事物。

Then, once as you start to build out an application with Grails, you will gradually get a deeper understanding of the technology Grails is built on in order to do more complex and powerful things. Slowly, you will work your way into Spring and Hibernate and build up an understanding of how things are put together under the covers, but you can be doing real things faster since you don't haveto know all of that from the beginning and can quickly make web applications in Grails the just work, especially with an understanding of the MVC architecture pattern with respect to an application responding to a web request.

然后,当您开始使用 Grails 构建应用程序时,您将逐渐对 Grails 构建的技术有更深入的了解,以便完成更复杂和更强大的事情。慢慢地,你会用自己的方式进入Spring和Hibernate和建立的事情是如何在幕后放在一起理解,但你可以更快地做实实在在的事情,因为你不具备了解所有的细节,从一开始和CAN快速使 Grails 中的 Web 应用程序成为正确的工作,尤其是在理解与响应 Web 请求的应用程序相关的 MVC 架构模式的情况下。

回答by loscuropresagio

The first thing I would suggest you to start with, given a knowledge of http protocol, is the JSP technology. Although you would probably use some framework like JSF2 for instance, it is important to start with JSP in order to well understand the technology and how to use it to deal with request/responses (that's my humble opinion of course).

考虑到 http 协议的知识,我建议您首先了解 JSP 技术。虽然您可能会使用一些框架,例如 JSF2,但重要的是从 JSP 开始,以便很好地理解该技术以及如何使用它来处理请求/响应(当然,这是我的拙见)。

Once you are familiar with JSP and, let's say, JSF 2.0 (you can find loads of documents on that topic) the next step is to try to connect with a data source. In Java EE technology there is a specification called JPA (Java Persistence API). JPA is just a specification for ORM (which is, roughly speaking, mapping an object java model with a set of DB tables)

一旦您熟悉了 JSP 和 JSF 2.0(您可以找到有关该主题的大量文档),下一步就是尝试连接数据源。在 Java EE 技术中有一个称为 JPA(Java Persistence API)的规范。JPA 只是 ORM 的一个规范(粗略地说,就是用一组 DB 表映射一个对象 java 模型)

Once you have your web application working with some basic pages and some operations on a DB you could enforce the security of your app introducing some security mechanisms.

一旦您的 Web 应用程序使用一些基本页面和数据库上的一些操作,您就可以通过引入一些安全机制来强制应用程序的安全性。

thisis a very good reference and start point for all of these topics and much more. It's a long path and it will take you some time. But, believe me, it's worth it!

是所有这些主题以及更多主题的非常好的参考和起点。这是一条漫长的道路,需要你一些时间。但是,相信我,这是值得的!

Good luck!

祝你好运!

回答by FAtBalloon

TO build a basic Java web application, go through this tutorial as it will explain the core foundational technologies with the standard Java EE platform and how to develop something real with them.

要构建一个基本的 Java Web 应用程序,请阅读本教程,因为它将解释标准 Java EE 平台的核心基础技术以及如何使用它们开发一些真正的东西。

http://netbeans.org/kb/docs/javaee/ecommerce/intro.html

http://netbeans.org/kb/docs/javaee/ecommerce/intro.html

It will demonstrate the standard Java web technologies such as EJBs, Servlets, JSP, JPA, and how to use Netbeans for your IDE.

它将演示标准的 Java Web 技术,例如 EJB、Servlet、JSP、JPA,以及如何将 Netbeans 用于您的 IDE。

Most beginner's are very overwhelmed by the thousands of different technologies and platforms out there with the Java EE framework. Java caters to a very 'open source' type of community and that means that you have ALOT of different choices and road maps on how you can build applications. This is very different from say the .NET world where everything is pretty straightforward and there's a very clean cookie cutter path.

大多数初学者都对 Java EE 框架的数千种不同技术和平台感到不知所措。Java 迎合了一个非常“开源”的社区类型,这意味着您有很多不同的选择和关于如何构建应用程序的路线图。这与 .NET 世界非常不同,在 .NET 世界中,一切都非常简单,并且有一个非常干净的千篇一律的路径。

Once you have learned these foundational basics by going through the tutorial, you will have a grasp on what the Java EE framework. Once you understand these basics, you can then start to learn about Maven or Spring and how those type of technologies can help you build better applications and you can make better and more educated decisions.

通过本教程学习这些基础知识后,您将掌握 Java EE 框架的内容。一旦您了解了这些基础知识,您就可以开始了解 Maven 或 Spring,以及这些类型的技术如何帮助您构建更好的应用程序,您可以做出更好、更有根据的决策。

GWT - Web interface tools. Some competing technologies: Spring, JSF, Wicket

GWT - Web 界面工具。一些竞争技术:Spring、JSF、Wicket

Hibernate - ORM mapping for databases. Competing technology: JPA

Hibernate - 数据库的 ORM 映射。竞争技术:JPA

Spring Architecture - Web Framework. Competing technology: JSF, Wicket, GWT

Spring 架构 - Web 框架。竞争技术:JSF、Wicket、GWT

Spring Roo - An MVC style flavor of Spring.

Spring Roo - Spring 的 MVC 风格风格。

JBoss - Application hosting. Competing technologies: Glassfish, Tomcat

JBoss - 应用程序托管。竞争技术:Glassfish、Tomcat

JPA - ORM mapping for databases. Competing technology: Hibernate

JPA - 数据库的 ORM 映射。竞争技术:Hibernate

POJO - Plain old java object. Just a simple object.

POJO - 普通的旧 java 对象。只是一个简单的对象。

Maven - Maven is a way to manage libraries or dependencies that your project uses. There's a central server that hosts many of these libraries and if you ever need to import a new one to use in your project, it's as simple as searching through the server and then copy and paste the configuration settings that they provide you into an XML document called the POM file or pom.xml

Maven - Maven 是一种管理项目使用的库或依赖项的方法。有一个中央服务器托管许多这些库,如果您需要导入一个新库以在您的项目中使用,只需搜索服务器,然后将它们提供的配置设置复制并粘贴到 XML 文档中称为 POM 文件或 pom.xml

回答by ccoakley

There are some very mature java libraries that each target a very small need in a web application. This means that many tutorials on the subject will have to pick and choose the libraries for each need. For someone just starting out from your position, this probably sucks.

有一些非常成熟的 Java 库,每个库都针对 Web 应用程序中非常小的需求。这意味着许多关于该主题的教程将不得不为每个需求挑选库。对于刚刚从您的职位开始的人来说,这可能很糟糕。

Naively, then, I searched for "java full stack framework" and found: Full stack framework for Java

然后,我天真地搜索“java full stack framework”并找到:Full stack framework for Java

The benefit of a full stack framework is that you don't have to choose each component. The framework has strong (perhaps rigid) opinions on how ORM is done, how templating is done, how mapping URLs to functions or actions is done, etc.

全栈框架的好处是您不必选择每个组件。该框架对如何完成 ORM、如何完成模板、如何将 URL 映射到函数或动作等方面有强烈的(也许是严格的)意见。

As for your list of technologies and acronyms:

至于您的技术和首字母缩略词列表:

GWT - a framework from google that focuses on the front end. Poorly stated, write your front end functionality in Java and have it magically transform into javascript.

GWT - 来自谷歌的一个专注于前端的框架。说得不好,用 Java 编写前端功能并让它神奇地转换为 javascript。

Hibernate (ORM connection?) - yep, store and load objects in your app.

休眠(ORM 连接?) - 是的,在您的应用程序中存储和加载对象。

Spring Architecture - Spring is pretty close to a full-stack framework, but it doesn't have as many rigid opinions on things. You can swap out templating engines, swap out ORM, etc. Not a bad framework, though. You might want to simply follow a tutorial on Spring (see below on Roo), and use the components suggested by the tutorial. Just know that you might find something else later that fills a particular niche.

Spring Architecture - Spring 非常接近于一个全栈框架,但它对事物没有那么多严格的意见。您可以更换模板引擎、更换 ORM 等。不过,这不是一个糟糕的框架。您可能只想遵循有关 Spring 的教程(请参阅下面关于 Roo 的内容),并使用教程建议的组件。只要知道你以后可能会发现其他东西来填补特定的利基。

Spring Roo (what is this?) - Spring Roo takes Spring and becomes opinionated (use what we say). This allows for less code on your part because it provides the code that integrates the various components. It still allows quite a bit of flexibility when you want to change something. Bonus, it comes with a nice tutorial.

Spring Roo(这是什么?) - Spring Roo 接受 Spring 并变得固执己见(使用我们所说的)。这允许您减少代码,因为它提供了集成各种组件的代码。当您想要更改某些内容时,它仍然具有相当大的灵活性。奖励,它带有一个很好的教程。

JBoss (servelet) - Usually I think of JBoss as an application container. Since the Java EE spec is a bit more complicated than simple CGI--there's a lot of things that need to be set up by the web server (loading classes, loading configuration files, connecting crap together)--JBoss does that stuff. Alternatives are Tomcat or Jetty.

JBoss (servelet) - 通常我认为 JBoss 是一个应用程序容器。由于 Java EE 规范比简单的 CGI 稍微复杂一点——Web 服务器需要设置很多东西(加载类、加载配置文件、将垃圾连接在一起)——JBoss 会做这些事情。替代方案是 Tomcat 或 Jetty。

JPA (ORM) - Yeah, it's a common set of interfaces that the various serialization providers might implement. It might be a database, it might be something else. But the idea is that your code for storing and retrieving objects would look the same.

JPA (ORM) - 是的,它是各种序列化提供程序可能实现的一组通用接口。它可能是一个数据库,也可能是其他东西。但这个想法是,用于存储和检索对象的代码看起来是一样的。

POJO (a style of using regular java objects with orm?) - In context, probably. "Plain Old Java Objects" are nice for any library. Sometimes a framework might require that you inherit your classes from some special class, like Model or Controller to work properly (also, HTTPServlet). This isn't good, because it restricts your own class hierarchy design and makes your own code less flexible. Consequently, things that work with POJOs are considered better.

POJO(一种在 orm 中使用常规 java 对象的风格?) - 在上下文中,可能。“Plain Old Java Objects”适用于任何库。有时,框架可能要求您从某些特殊类(例如 Model 或 Controller)继承您的类才能正常工作(还有 HTTPServlet)。这不好,因为它限制了您自己的类层次结构设计并使您自己的代码不那么灵活。因此,使用 POJO 的东西被认为更好。

Maven - Maven is a tool that helps manage dependencies. Without it, java has its own form of DLL hell. Library A depends on version 1.1 of Library B, but Library C depends on version 1.5 of Library B. Ohhh crap, time to read through a tutorial on classloaders. Don't worry too much, though, any tutorial on java web apps is likely to tell you exactly what you need to download and use.

Maven - Maven 是一种帮助管理依赖项的工具。没有它,java 有自己的 DLL 地狱形式。库 A 依赖于库 B 的 1.1 版,但库 C 依赖于库 B 的 1.5 版。哦,废话,是时候阅读有关类加载器的教程了。不过不要太担心,任何关于 Java Web 应用程序的教程都可能会告诉您确切需要下载和使用的内容。

回答by Rick Mangi

Vijay's answer above is pretty much spot on. I'll elaborate on a few points.

上面 Vijay 的回答非常到位。我将详细说明几点。

Most of the "fameworks" that you mention, spring, roo (which is just a way to work with spring), gwt, struts, etc. all work on top of "Java EE". Java EE is Sun (now oracle's) term for the "standard" way to work with web applications. Java EE also includes a lot of more enterprise stuff like EJBs, JMS, JMX which you won't really need to concern yourself with unless you're doing very high end stuff.

您提到的大多数“fameworks”、spring、roo(这只是使用 spring 的一种方式)、gwt、struts 等都在“Java EE”之上工作。Java EE 是 Sun(现在是 oracle 的)术语,表示使用 Web 应用程序的“标准”方式。Java EE 还包括很多企业级的东西,比如 EJB、JMS、JMX,除非你做的是非常高端的东西,否则你真的不需要关心这些东西。

JSP is the part that will be most familiar to you coming from PHP, it's a way of embedding code inside of an HTML page.

JSP 是您最熟悉 PHP 的部分,它是一种在 HTML 页面中嵌入代码的方式。

Servlets are the middle tier, that's where database connections are created and application logic happens. As it turns out, JSPs are converted into Servlets at compile time.

Servlet 是中间层,它是创建数据库连接和应用程序逻辑发生的地方。事实证明,JSP 在编译时被转换为 Servlet。

All Java EE stuff runs inside of a "servlet container" or an "application server". That's the big difference between java and php. Your choices here are usually Tomcat, JBoss or Jetty.

所有 Java EE 的东西都在“servlet 容器”或“应用程序服务器”中运行。这就是 java 和 php 之间的巨大区别。您在这里的选择通常是 Tomcat、JBoss 或 Jetty。

Maven is a build system that helps you to manage 3rd party jar files (libraries) and compiles and runs your test codes. It has plugins to deploy your code to tomcat/jboss/jetty.

Maven 是一个构建系统,可帮助您管理 3rd 方 jar 文件(库)并编译和运行您的测试代码。它有将代码部署到 tomcat/jboss/jetty 的插件。

POJO stands for "Plain old java object". Most modern frameworks try to shield you from the complexities of what happens under the hood and let you work with "POJOS". This comes into play when working with something like spring or hibernate. You may also see the term "java bean" tossed around, that's a standard way of defining "pojos" that just sets up a convention about how to name getter/setter methods and constructors.

POJO 代表“Plain old java object”。大多数现代框架都试图让您免受幕后发生的复杂情况的影响,并让您使用“POJOS”。这在使用 spring 或 hibernate 之类的东西时会起作用。您可能还会看到“java bean”这个词到处乱扔,这是定义“pojos”的标准方式,它只是建立了一个关于如何命名 getter/setter 方法和构造函数的约定。

I would recommend getting a book on getting started with JSPs/Servlets and starting there.

我建议你买一本关于 JSP/Servlet 入门的书,然后从那里开始。

回答by jabu.10245

I suggest you google those keywords and look for some books and tutorials.

我建议你用谷歌搜索这些关键词并寻找一些书籍和教程。

Mavenis a tool for managing your Java projects and artifacts (JARs, WARs, etc.). I'd start learning Maven first, so that you have a foundation to create your Java projects on. It also handles your dependency management: you just specify what JARs you need in your application and Maven will download them for you.

Maven是一种用于管理 Java 项目和工件(JAR、WAR 等)的工具。我会先开始学习 Maven,这样你就有了创建 Java 项目的基础。它还处理您的依赖项管理:您只需在应用程序中指定您需要的 JAR,Maven 将为您下载它们。

JPA(Java Persistence API) handles the Object-Relational-Mapping of your entities. You can write POJOs (plain old Java objects) and map them to your database tables.

JPA(Java Persistence API)处理实体的对象关系映射。您可以编写 POJO(普通的旧 Java 对象)并将它们映射到您的数据库表。

Hibernateis a JPA provider (i.e. implementation of JPA). Usually you don't have to deal with Hibernate that much, most of the time you can use JPA directly. You just configure the JPA provider in the persistence.xmlconfig file.

Hibernate是一个 JPA 提供者(即 JPA 的实现)。通常你不用和 Hibernate 打交道那么多,大多数时候你可以直接使用 JPA。您只需在persistence.xml配置文件中配置 JPA 提供程序。

CDI(Context and Dependency Injection) see description. CDI "wires" the components of your application together.

CDI(上下文和依赖注入)见描述。CDI 将应用程序的组件“连接”在一起。

Springframeworkstarted as a framework to offer Dependency Injection capabilities, but today it's much more than that. The WebMVCmodule of spring might be interesting to you. You can write Controllers and Views (using JSP for example).

Springframework最初是一个提供依赖注入功能的框架,但今天它远不止于此。在WebMVC春天的模块可能是有趣的你。您可以编写控制器和视图(例如使用 JSP)。

Servlet APIA servlet acts like a little server, handling a HTTP request and generating the response. You can write your own servlets or use a web framework to do it's job, for example Spring's DispatcherServlet or Java Server Faces, or whatever framework.

Servlet APIservlet 就像一个小服务器,处理 HTTP 请求并生成响应。您可以编写自己的 servlet 或使用 Web 框架来完成它的工作,例如 Spring 的 DispatcherServlet 或Java Server Faces或任何框架。

JSPis a technology to write templates for your HTML files. JSP files are being compiled into Java classes and can contain HTML code, JSP-specific XML code and Java code. Example:

JSP是一种为 HTML 文件编写模板的技术。JSP 文件被编译成 Java 类,可以包含 HTML 代码、特定于 JSP 的 XML 代码和 Java 代码。例子:

<ul>
    <c:forEach items="${countries}" var="country">
        <li>${country}</li>
    </c:forEach>
</ul>

renders a list of countries, where ${countries}might be a collection of country objects (or strings in this case).

呈现国家列表,其中${countries}可能是国家对象的集合(或在本例中为字符串)。

JSF(Java Server Faces) is another framework for building web applications, utilizing JSP and/or XHTML for defining the views and backing beans for the backend part. I would start learning with JSP instead of JSF, it's easier to learn.

JSF(Java Server Faces)是另一种构建 Web 应用程序的框架,它利用 JSP 和/或 XHTML 来定义视图和后端部分的支持 bean。我会开始学习 JSP 而不是 JSF,它更容易学习。

Most of the frameworks are part of the JavaEE standards portfolio. For stuff like CDI to work you need either an application server (like JBoss AS) or at least a server with a servlet container (like Apache Tomcat or Jetty) in combination with Spring.

大多数框架都是 JavaEE 标准组合的一部分。对于像 CDI 这样的东西,你需要一个应用服务器(比如 JBoss AS)或者至少一个带有 servlet 容器的服务器(比如 Apache Tomcat 或 Jetty)与 Spring 结合使用。

Spring and Hibernate are not standard, but they implement many of the standard APIs nowadays.

Spring 和 Hibernate 不是标准的,但它们实现了当今许多标准的 API。

**EDIT: ** you might also want to learn about Annotations in Java code. They are around since Java 5 and are widely used as an alternative to XML based configuration.

**编辑:** 您可能还想了解 Java 代码中的注释。它们自 Java 5 以来就存在,并被广泛用作基于 XML 的配置的替代方案。



So my suggestion is that you start learning Maven (not necessary tho, you can also manage your project manually), then Spring and JSP to be able to create a simple web application and then JPA/Hibernate to make your data persistent.

所以我的建议是你开始学习 Maven(不是必需的,你也可以手动管理你的项目),然后是 Spring 和 JSP 能够创建一个简单的 Web 应用程序,然后是 JPA/Hibernate 来使你的数据持久化。

In my opinion learning Spring is much easier than learning the whole JavaEE APIs, since Spring is quite good documented.

在我看来,学习 Spring 比学习整个 JavaEE API 容易得多,因为 Spring 有很好的文档记录

回答by Ann Addicks

Wow, not only is this an open ended question, but it could have pages and pages of answers. I worked in php ~ 7 years ago without a framework so I'll try to point you in some starting directions and compare my experience (which is outdated and sans framework!)

哇,这不仅是一个开放式问题,而且它可以有一页又一页的答案。7 年前,我在没有框架的情况下在 php 中工作,所以我会尝试为您指出一些开始的方向并比较我的经验(这是过时且没有框架的!)

You need an application server just like your Apache server for your Java web app, such as Tomcat, Jboss or Glassfish. These servers handle serving dynamic content.

您需要一个应用程序服务器,就像您的 Java Web 应用程序的 Apache 服务器一样,例如 Tomcat、Jboss 或 Glassfish。这些服务器处理提供动态内容。

On top of the server you have your web frameworks which you've mentioned GWT, Spring, and Spring Roo. Spring Roo is like Rails, but in Java. GWT goes all out and and will write your html/javascript code based on your Java code.

在服务器之上,您有您提到的 GWT、Spring 和 Spring Roo 的 Web 框架。Spring Roo 类似于 Rails,但使用的是 Java。GWT 全力以赴,并将根据您的 Java 代码编写您的 html/javascript 代码。

In Spring You can define objects to be used in your forms and then when they are submitted the entire object is passed back so there is less work. I remember the days of getting a lot of $_POST[] stuff and I'm thankful not to have to do that when using spring. There is Spring Security that you can use for auth.

在 Spring 中,您可以定义要在表单中使用的对象,然后当它们被提交时,整个对象被传回,因此工作量减少。我记得有很多 $_POST[] 东西​​的日子,我很庆幸在使用 spring 时不必这样做。您可以使用 Spring Security 进行身份验证。

The web frameworks are configured to connect to the database and then there is the database abstraction ORM, Hibernate. In PHP I used EZSQL for abstraction which didn't contain nearly the amount of features Hibernate does. Hibernate has a steep learning curve, but is worth learning.

Web 框架配置为连接到数据库,然后是数据库抽象 ORM,Hibernate。在 PHP 中,我使用 EZSQL 进行抽象,它不包含 Hibernate 所做的几乎所有功能。Hibernate 有一个陡峭的学习曲线,但值得学习。

For dynamic GUI's you'll probably want to research JSP, but may be interested in learning JSF.

对于动态 GUI,您可能想研究 JSP,但可能对学习 JSF 感兴趣。

If I were you, I'd pick an application server, maybe tomcat, then a web framework to play around with, personally I'd go with Spring. The framework will probably have dynamic GUI examples so you'll pick up jsp/jsf. Then possibly add the ORM and a build tool to build externally from your IDE, such as Maven, Ant, or Gradle.

如果我是你,我会选择一个应用服务器,也许是 tomcat,然后是一个 web 框架来玩,我个人会选择 Spring。该框架可能会有动态 GUI 示例,因此您将选择 jsp/jsf。然后可能添加 ORM 和构建工具以从您的 IDE 外部构建,例如 Maven、Ant 或 Gradle。