且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java/Jakarta EE Web 开发,我从哪里开始,我需要什么技能?

更新时间:2023-12-04 07:58:10

(2021 年 4 月更新)

首先,Java EE"自 2019 年 9 月起更名为Jakarta EE",从版本 8 开始.其中涵盖了 1.2 版到 1.4 版.Java EE"涵盖版本 5 到 8.另请参阅Java 平台、企业版、***历史.

我到底需要学习什么?

我假设您已经熟悉客户端技术,例如 HTMLCSSJS,所以我不会详细说明.我还假设您已经熟悉基本的 Java.遵循 Oracle 的 Java 教程,如果可能,请获取 OCP 书籍或课程.

然后就可以从JSP/Servlet开始学习Java web开发的基本概念了.好的教程可以在 Jakarta EE 教程第 18 章Jakarta Servlet 技术"中找到>.请注意,从 Java EE 6 开始,JSP 已从教程中删除,以支持 JSF 并且那个 JSP 从那时起基本上没有改变.这就是为什么您可以安全地使用相当旧的 Java EE 5 教程为了这.关于 JSP 最重要的一点是,自 2003 年以来,官方不鼓励使用 <% scriptlets %> 在 JSP 文件中编写纯 Java 代码.另见 如何使用 JSP 2 避免 JSP 文件中的 Java 代码?因此,应该跳过任何仍然涵盖 scriptlet 的教程,因为它们肯定会让您陷入学习不良做法的恶性循环.

在 Stack Overflow 上,您还可以找到关于 JSPServletsJSTLEL 在这里您可以了解基本知识并找到更多有用的链接.


Tomcat 似乎是一个很好的 Java 网络服务器.

是的.然而,它的能力有限.它基本上是一个准系统的 servlet 容器,仅实现了巨大的 Java EE API 的 JSP/Servlet 部分.如果您想使用 EJB 或 JPA,那么您想选择另一个,例如WildFlyTomEEa>、PayaraLibertyWebLogic 等.否则你必须使用 Spring 而不是 Java EE.也就是说,如果不修改核心引擎,就不可能在准系统 servlet 容器中安装 EJB,在 Tomcat 的情况下,您基本上是在重新发明 TomEE.另请参见 Java EE 到底是什么?如何通过Maven正确安装和配置JSF库?如何在Tomcat上安装和使用CDI?>


我知道有用于 ORM 的 Hibernate.

以前在 J2EE 时代,JPA 不存在,EJB2 很糟糕的时候,Hibernate 是一个独立的框架,经常与 Spring 结合使用来取代 EJB.自从在 Java EE 5 (2006) 中引入 JPA 以来,Hibernate 已经成为一个 JPA 实现.您可以在 Jakarta EE 教程第 VIII 部分 学习 JPA.此外,基于从 Spring 吸取的经验教训,EJB3 得到了很大改进.另请参阅何时需要或方便使用 Spring 或 EJB3 或同时使用它们?


Java 有 MVC 吗?JSP呢?MVC 和 JSP 可以在一起吗?JavaBeans?

您可以,但是重新发明*** 当涉及到将模型与视图绑定时(转换、验证、更改侦听器等).Jakarta EE 的 MVC 框架称为 JSF.在 Java EE 6 之前,它曾经在 JSP 上运行,这是一种相当传统的视图技术.JSP 已被 Facelets 取代.您可以在 Jakarta EE 教程第 III 部分第 7 - 17 章 中学习 JSF.顺便说一下,你也可以在Tomcat上使用JSF,你只需要单独安装它.安装说明可以在 Mojarra 主页 找到.WildFly、TomEE、Payara、Liberty、WebLogic 等作为完整的 Jakarta EE 实现已经提供开箱即用的 JSF(和 CDI、BV、JSONP、JAX-RS、EJB、JPA 等),因此您不需要单独安装.另请参阅 如何通过 Maven 正确安装和配置 JSF 库?


也许是一本涵盖所有这些内容的书?

有几本书.我建议从一本书开始,专注于 Jakarta EE一般,一本更侧重于 JSF 和一本书 更侧重于 JPA一>.确保您选择涵盖该主题的最新书籍.首先调查最新的可用版本,然后确保所选书籍涵盖了该版本.因此,绝对不要选择 Java EE 5 或 JSF 1.0 左右的旧书,而目前已经有 Jakarta EE 8 和 JSF 2.3.

最后但并非最不重要的一点,请忽略由业余爱好者维护的主要关注广告收入而不是教学的代码片段抓取网站,例如roseindia、tutorialspoint、javabeat、journaldev、javatpoint、codejava等.它们很容易通过干扰识别广告链接/横幅和包含 scriptlets 的 JSP 代码片段.

另见:

I want to learn, at least at a basic level, how to build Java web applications (coming from a .NET background). I would like to be able to build, deploy a simple CMS type application from the ground up.

What exactly do I need to learn?

Tomcat seems to be a good web server for Java.

What options are there for the web? I know there is Hibernate for an ORM.

Does Java have MVC? What about JSP? Can MVC and JSP be together? NetBeans?

Maybe a book that covers all of these?

(Updated Apr 2021)

First of all, "Java EE" has since Sep 2019 been renamed to "Jakarta EE", starting with version 8. Historically, there was also the term "J2EE" which covered versions 1.2 until 1.4. The "Java EE" covered versions 5 until 8. See also Java Platform, Enterprise Edition, History on Wikipedia.

What exactly do I need to learn?

I assume that you're already familiar with client side technologies like HTML, CSS and JS, so I won't go in detail with that. I also assume that you're already familiar with basic Java. Follow Oracle's The Java Tutorials and if possible, go get a OCP book or course as well.

Then you can start with JSP/Servlet to learn the basic concepts of Java web development. Good tutorial can be found in Jakarta EE tutorial chapter 18 'Jakarta Servlet Technology'. Note that since Java EE 6, JSP is removed from the tutorial in favor of JSF and that JSP has basically not changed since then. That's why you could safely use the fairly old Java EE 5 tutorial for this. Most important thing with regard to JSP is the fact that writing plain Java code in JSP files using <% scriptlets %> is officially discouraged since 2003. See also How can I avoid Java code in JSP files, using JSP 2? So any tutorials which still cover scriptlets should be skipped as they will definitely take you into a downward spiral of learning bad practices.

Here on Stack Overflow, you can also find nice wiki pages about JSP, Servlets, JSTL and EL where you can learn the essentials and find more useful links.


Tomcat seems to be a good web server for Java.

It is. It is however limited in capabilities. It's basically a barebones servlet container, implementing only the JSP/Servlet parts of the huge Java EE API. If you ever want to go EJB or JPA, then you'd like to pick another, e.g. WildFly, TomEE, Payara, Liberty, WebLogic, etc. Otherwise you have to use Spring instead of Java EE. It's namely not possible to install EJB in a barebones servlet container without modifying the core engine, you'd in case of Tomcat basically be reinventing TomEE. See also What exactly is Java EE?, How to properly install and configure JSF libraries via Maven? and How to install and use CDI on Tomcat?


I know there is Hibernate for an ORM.

Previously, during the J2EE era, when JPA didn't exist and EJB2 was terrible, Hibernate was a standalone framework and often used in combination with Spring to supplant EJB. Since the introduction of JPA in Java EE 5 (2006), Hibernate has become a JPA implementation. You can learn JPA at Jakarta EE tutorial part VIII. Also, EJB3 was much improved based on lessons learnt from Spring. See also When is it necessary or convenient to use Spring or EJB3 or all of them together?


Does Java have MVC? What about JSP? Can MVC and JSP be together? JavaBeans?

You can, but that's a lot of reinvention of the wheel when it comes to tying the model with the view (conversion, validation, change listeners, etc). Jakarta EE's MVC framework is called JSF. Prior to Java EE 6 it used to run on JSP, which is a fairly legacy view technology. JSP is been replaced by Facelets. You can learn JSF at Jakarta EE tutorial part III chapters 7 - 17. You can by the way also use JSF on Tomcat, you only have to install it separately. Installation instructions can be found at Mojarra homepage. WildFly, TomEE, Payara, Liberty, WebLogic, etc as being a complete Jakarta EE implementation already provide JSF (and CDI, BV, JSONP, JAX-RS, EJB, JPA, etc) out the box, so you don't need to install it separately. See also How to properly install and configure JSF libraries via Maven?


Maybe a book that covers all of these?

There are several books. I would recommend to start with a book focused on Jakarta EE in general, a book more focused on JSF, and a book more focused on JPA. Ensure that you choose the most recent book covering the subject. First investigate the most recent available version and then ensure that the chosen book covers that. Thus do definitely not pick an old book for Java EE 5 or JSF 1.0 or so while there's currently already Jakarta EE 8 and JSF 2.3 available.

Last but not least, please ignore code snippet scraping sites maintained by amateurs with primary focus on advertisement income instead of on teaching, such as roseindia, tutorialspoint, javabeat, journaldev, javatpoint, codejava, etc. They are easily recognizable by disturbing advertising links/banners and JSP code snippets containing scriptlets.

See also: