简单的 Java Web 框架
我想了解有关 Java 的 Web 开发。使用 PHP 和 Apache 非常容易,但我需要使用 Java。
我搜索过 Java Web 框架,但其中许多都很复杂且难以配置。我需要像 PHP 和 Apache 一样简单的东西。
Tomcat和Jetty不使用端口80,我必须保留一个进程将连接重定向到另一个端口,并且从一个端口到另一个端口的传输效率很低。然而,Apache自然而然地使用80端口。
有些框架使用包含许多配置文件夹和文件的复杂目录结构。其中一些对每个文件夹使用应用程序的概念。对于 Apache,这非常简单,因为每个页面都是“/var/www/”中的一个文件。
我对 servlet、JSP、JSF 或 Java 企业版一无所知。我更喜欢在同一个文件中混合静态 HTML 和动态生成的 HTML,但如果我必须多次调用 Java 函数来输出 HTML 字符串,那也没关系。
我想了解一个简单的 Java Web 框架。用于侦听端口 80、解释 HTTP 协议并显示由 Java 代码生成的 HTML 的东西。操作系统是Linux(Ubuntu),我不使用IDE。
谢谢
Possible Duplicate:
Can anyone recommend a simple Java web-app framework?
I want to know about web development with Java. It is very easy to work with PHP and Apache, but I need to use Java.
I have searched for Java web frameworks, but many of them are complex and difficult to configure. I need something as simple as PHP with Apache.
Tomcat and Jetty do not use the port 80, I have to keep a process to redirect connections to another port, and a transfer from a port to another port is inefficient. However, Apache uses port 80 naturally.
There are frameworks that use a complex directory structure with many configuration folders and files. Some of them use the concept of application for each folder. With Apache, it is very simple, because each page is a file in "/var/www/".
I do not know anything about servlet, JSP, JSF or Java Enterprise Edition. I prefer something that mix static HTML and dynamically-generated HTML in the same file, but if I have to call a Java function many times to output HTML string, it's ok.
I want to know a simple Java Web Framework. Something to listen the port 80, interpret the HTTP protocol and show the HTML that is generated by the Java code. The OS is Linux (Ubuntu) and I do not use IDE.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在端口 80 上运行 Tomcat/Jetty。只需编辑 server.xml(对于 Tomcat)。在 Unix/Linux 上端口号 < 1024 用于特权用户,因此您需要以 root 身份运行 tomcat。
此外,运行 Java Web 应用程序与使用 LAMP(或类似)堆栈略有不同。您仍然需要了解 Web/Servlet 容器的概念
http://en.wikipedia.org/wiki /Servlet_container
熟悉 WAR(Web 存档)文件的典型结构。这与了解 Apache 的工作原理并通过使用 LAMP 堆栈来熟悉基本的 Apache 配置没有什么不同。
这是涉足 Java Web 开发时最起码应该做的事情。
看看web4j http://www.web4j.com/ 我没用过但看起来很简单足以满足您的需求,应该可以帮助您入门
You can run Tomcat/Jetty on port 80. Just edit the server.xml (for Tomcat). On Unix/Linux port numbers < 1024 are for privileged users so you would need to run tomcat as root.
Also, running Java web apps is a little bit different than using a LAMP (or a similar) stack. You do still need to understand the concept of a Web/Servlet container
http://en.wikipedia.org/wiki/Servlet_container
Familiarize yourself with the a typical structure for a WAR (Web Archive) file. This is no different than learning about how Apache works and familiarizing oneself with basic Apache configuration with working with a LAMP stack.
This is the bare minimum one should do when venturing into Java Web development.
Take a look at web4j http://www.web4j.com/ I have never used it but it looks simplistic enough for your needs and should get you started
查看 Play:http://www.playframework.org/
我听说过一些关于它的好消息。
Check out Play: http://www.playframework.org/
I've heard good things about it.
根据您的要求,我认为 JSP 就可以满足您的需求。它应该相对容易学习,允许您将动态内容与静态 HTML 混合,可以像 PHP 脚本一样直接访问(如果放置在正确的文件夹中),并且还允许您调用 Java 函数。
虽然它需要一些专业知识,但您也可以在这里查看 mod_jk: http://diegobenna.blogspot.com/2011/01/connect-tomcat-7-with-apache2-modjk-and.html
它允许您与 Apache 一起运行 tomcat,因此您可以Apache 和 Tomcat 并行运行。
Based on your requirement, I think JSP is all you need. It should be relatively easy to learn and lets you mix dynamic content with static HTML, can be directly accesible just like PHP scripts(If placed in correct folder), and also lets you call Java functions.
Although it requires a bit of expertise, but you can also take a look at mod_jk here: http://diegobenna.blogspot.com/2011/01/connect-tomcat-7-with-apache2-modjk-and.html
It lets you run tomcat alongside Apache, so you have both Apache and Tomcat running side by side.
您可能需要使用 Jetty 来部署您的 servlet。由于您不使用 IDE,因此如果您使用 maven ,能够运行
mvn 是很神奇的jetty:run
并测试您的应用程序(在任何端口上)。我还推荐使用 Maven 作为生成 WAR 文件的简单方法。 Jersey 是一个轻量级的 REST 框架。如果您不受 Java 的限制,而是受 JVM 的限制,我建议您查看 Scala 的 Scalatra。
Tomcat 和 Jetty 默认情况下可能不使用 80 端口,但它们肯定能够使用 80 端口。
You will probably want to use Jetty to deploy your servlet. Since you don't use an IDE, if you use maven it's magical to be able to run
mvn jetty:run
and test your application (on any port). I also recommend maven as an easy way to generate WAR files. Jersey is a light-weight REST framework.If you are not constrained to Java but rather are constrained to the JVM, I recommend looking at Scalatra for Scala.
Tomcat and Jetty may not use port 80 by default, but they are certainly capable of using port 80.