你如何用Java制作网站?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/621228/
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
How do you make websites with Java?
提问by
This might be a really trivial question, but I've been writing Java programs at my school and I just found out that I can create websites with Java as well.
这可能是一个非常微不足道的问题,但我一直在我的学校编写 Java 程序,我刚刚发现我也可以用 Java 创建网站。
- How can I do that? Any good books/tutorials for that?
- Which is better for Web development, Java or PHP?
- Also, when using PHP, MySQL comes into picture and while writing Java programs for desktop, we just use File I/O, so what is better for web dev, File I/O or MySQL?
- 我怎样才能做到这一点?有什么好书/教程吗?
- Java 和 PHP 哪个更适合 Web 开发?
- 此外,在使用 PHP 时,MySQL 会出现,而在为桌面编写 Java 程序时,我们只使用文件 I/O,那么 Web 开发、文件 I/O 或 MySQL 哪个更好?
采纳答案by cletus
Read the tutorial on Java Web applications.
Basically Web applications are a part of the Java EE standard. A lot of people only use the Web (servlets) part with additional frameworks thrown in, most notably Spring but also Struts, Seam and others.
基本上,Web 应用程序是 Java EE 标准的一部分。很多人只使用 Web (servlet) 部分和其他框架,最显着的是 Spring,还有 Struts、Seam 和其他框架。
All you need is an IDE like IntelliJ, Eclipse or Netbeans, the JDK, the Java EE download and a servlet container like Tomcat (or a full-blown application server like Glassfish or JBoss).
您只需要一个像 IntelliJ、Eclipse 或 Netbeans 这样的 IDE、JDK、Java EE 下载和一个像 Tomcat 这样的 servlet 容器(或者像 Glassfish 或 JBoss 这样的成熟的应用程序服务器)。
Here is a Tomcat tutorial.
这是Tomcat 教程。
回答by devinfoley
You are asking a few different questions...
你在问几个不同的问题...
- How can I create websites with Java?
- 如何使用 Java 创建网站?
The simplest way to start making websites with Java is to use JSP. JSP stands for Java Server Pages, and it allows you to embed HTML in Java code files for dynamic page creation. In order to compile and serve JSPs, you will need a Servlet Container, which is basically a web server that runs Java classes. The most popular basic Servlet Container is called Tomcat, and it's provided free by The Apache Software Foundation. Follow the tutorial that cletus provided here.
开始使用 Java 制作网站的最简单方法是使用 JSP。JSP 代表 Java Server Pages,它允许您在 Java 代码文件中嵌入 HTML 以创建动态页面。为了编译和提供 JSP,您需要一个 Servlet 容器,它基本上是一个运行 Java 类的 Web 服务器。最流行的基本 Servlet 容器称为 Tomcat,它由 Apache 软件基金会免费提供。按照此处cletus 提供的教程进行操作。
Once you have Tomcat up and running, and have a basic understanding of how to deploy JSPs, you'll probably want to start creating your own JSPs. I always like IBM developerWorks tutorials. They have a JSP tutorial herethat looks alright (though a bit dated).
一旦您启动并运行了 Tomcat,并且对如何部署 JSP 有了基本的了解,您可能想要开始创建您自己的 JSP。我一直喜欢 IBM developerWorks 教程。他们在这里有一个 JSP 教程,看起来不错(虽然有点过时)。
You'll find out that there is a lot more to Java web development than JSPs, but these tutorials will get you headed in the right direction.
您会发现 Java Web 开发比 JSP 多得多,但这些教程将使您朝着正确的方向前进。
- PHP vs. Java
- PHP 与 Java
This is a pretty subjective question. PHP and Java are just tools, and in the hands of a bad programmer, any tool is useless. PHP and Java both have their strengths and weaknesses, and the discussion of them is probably outside of the scope of this post. I'd say that if you already know Java, stick with Java.
这是一个相当主观的问题。PHP和Java只是工具,在一个糟糕的程序员手中,任何工具都是无用的。PHP 和 Java 都有其优点和缺点,对它们的讨论可能超出了本文的范围。我会说,如果您已经了解 Java,请坚持使用 Java。
- File I/O vs. MySQL
- 文件 I/O 与 MySQL
MySQL is better suited for web applications, as it is designed to handle many concurrent users. You should know though that Java can use MySQL just as easily as PHP can, through JDBC, Java's database connectivity framework.
MySQL 更适合 Web 应用程序,因为它旨在处理许多并发用户。您应该知道,通过 Java 的数据库连接框架 JDBC,Java 可以像 PHP 一样轻松地使用 MySQL。
回答by Jan Gressmann
Also be advised, that while Java is in general very beginner friendly, getting into JavaEE, Servlets, Facelets, Eclipse integration, JSP and getting everything in Tomcat up and running is not. Certainly not the easiest way to build a website and probably way overkill for most things.
On top of that you may need to host your website yourself, because most webspace providers don't provide Servlet Containers. If you just want to check it out for fun, I would try Ruby or Python, which are much more cooler things to fiddle around with. But anyway, to provide at least something relevant to the question, here's a nice Servlet tutorial: link
还请注意,虽然 Java 通常对初学者非常友好,但进入 JavaEE、Servlets、Facelets、Eclipse 集成、JSP 并在 Tomcat 中启动和运行所有内容并非如此。当然,这不是建立网站的最简单方法,而且对于大多数事情来说可能有点矫枉过正。
最重要的是,您可能需要自己托管您的网站,因为大多数网络空间提供商不提供 Servlet 容器。如果你只是想看看它的乐趣,我会尝试 Ruby 或 Python,它们是更酷的东西。但无论如何,为了至少提供与问题相关的内容,这里有一个很好的 Servlet 教程:链接
回答by Esko
While a lot of others should be mentioned, Apache Wicketshould be preferred.
虽然应该提到很多其他人,但Apache Wicket应该是首选。
Wicket doesn't just reduce lots of boilerplate code, it actually removes it entirely and you can work with excellent separation of business code and markup without mixing the two and a wide variety of other things you can read about from the website.
Wicket 不仅减少了大量样板代码,它实际上完全删除了它,您可以很好地分离业务代码和标记,而无需将两者以及您可以从网站上阅读的各种其他内容混合在一起。
回答by Hanno Fietz
I'll jump in with the notorious "Do you really want to do that" answer.
我会用臭名昭著的“你真的想这样做吗”的答案来回答。
It seems like your focus is on playing with Java and seeing what it can do. However, if you want to actually develop a web app, you should be aware that, although Java is used in web applications (and in serious ones), there are other technology options which might be more adequate.
看起来您的重点是玩 Java 并看看它可以做什么。但是,如果您想真正开发一个 Web 应用程序,您应该意识到,尽管 Java 用于 Web 应用程序(并且在严肃的应用程序中),但还有其他技术选项可能更合适。
Personally, I like (and use) Java for powerful, portable backend services on a server. I've never tried building websites with it, because it never seemed the most obvious ting to do. After growing tired of PHP (which I have been using for years), I lately fell in love with Django, a Python-based web framework.
就我个人而言,我喜欢(并使用)Java 在服务器上提供强大的、可移植的后端服务。我从来没有尝试过用它来建立网站,因为它似乎从来都不是最明显的事情。在厌倦了 PHP(我已经使用了多年)之后,我最近爱上了Django,一个基于 Python 的 Web 框架。
The Ruby on Rails people have a number of very funny videos on youtubecomparing different web technologies to RoR. Of course, these are obviously exaggerated and maybe slightly biased, but I'd say there's more than one grain of truth in each of them. The one about Java is here. ;-)
Ruby on Rails 人员在 youtube上有许多非常有趣的视频,将不同的 Web 技术与 RoR 进行比较。当然,这些显然被夸大了,可能略有偏见,但我想说,每一个都有不止一个道理。关于 Java 的一个在这里。;-)
回答by Nikhil Chelliah
回答by Valignus
Look into creating Applets if you want to make a website with Java. You most likely wont need to use anything but regular Java, unless you want something more specialized.
如果您想使用 Java 制作网站,请考虑创建小程序。除了常规 Java 之外,您很可能不需要使用任何东西,除非您想要更专业的东西。