简体   繁体   English

使用Java而不使用Servlet和Tomcat创建简单的网页

[英]Creating a simple web page using Java without using Servlet and Tomcat

I want to create a simple server application which runs on the desktop, and when I type my ip and port on the web browser, it connects to the server client which then opens a webpage with appropriate displays coded on the server application. 我想创建一个运行在桌面上的简单服务器应用程序,当我在网络浏览器中键入ip和端口时,它将连接到服务器客户端,然后客户端将打开一个网页,并在服务器应用程序上编码适当的显示内容。

I read online that I need to use servlet and Apache Tomcat to make a webpage using Java. 我在网上阅读了我需要使用servlet和Apache Tomcat来使用Java制作网页的信息。

I am wondering if there are any easier way to make a simple webpage which can contain buttons without using servlet and Apache Tomcat? 我想知道是否有更简单的方法来制作一个简单的网页,其中可以包含按钮而无需使用servlet和Apache Tomcat?

For example, I can use sockets to communicate between server and client applications. 例如,我可以使用套接字在服务器和客户端应用程序之间进行通信。 Could I change this client into typing the ip address and port on the web browser which will display a webpage created and contained in the server application and remove the need for servlet and tomcat? 我是否可以更改此客户端,以在Web浏览器中键入IP地址和端口,从而显示在服务器应用程序中创建并包含的网页,并不需要servlet和tomcat? If so, how do I create a button on the server application so that web browser can see the button when connecting to the server application? 如果是这样,如何在服务器应用程序上创建按钮,以便Web浏览器在连接到服务器应用程序时可以看到该按钮?

Thank you very much. 非常感谢你。

If I understand you correctly, you want to have a web page, but you don't want to use Tomcat (or any other servlet engine). 如果我对您的理解正确,那么您希望拥有一个网页,但是不想使用Tomcat(或任何其他servlet引擎)。

Although it is technically possible to write your own little web server (using server sockets etc), but what you're basically doing then is rewriting Tomcat. 尽管从技术上来说,可以编写自己的小型Web服务器(使用服务器套接字等),但是基本上要做的就是重写Tomcat。 Writing a good web server is a daunting job, and should not be taken lightly. 编写好的Web服务器是一项艰巨的任务,不应轻易掉以轻心。 I think you are underestimating that. 我认为您低估了这一点。 Instead, use what is already there. 相反,请使用已经存在的内容。 Tomcat is really quite easy get running. Tomcat确实很容易运行。

Creating the server piece could be done with raw sockets, but I would look at at an embedded server like Jetty. 可以使用原始套接字来完成服务器部分的创建,但是我将看一看诸如Jetty之类的嵌入式服务器。 I think it will save you a lot of time and headache. 我认为这将为您节省很多时间和头痛。

http://docs.codehaus.org/display/JETTY/Embedding+Jetty http://docs.codehaus.org/display/JETTY/Embedding+Jetty

You should look into Play Framework . 您应该研究Play Framework It will be easier then implementing Tomcat or Apache. 实施Tomcat或Apache将更加容易。

Version 1.2.4 is stable and feature-complete for Java, version 2.x is focused on Scala and doesn't have all the features of 1.2.4 yet. 1.2.4版对于Java是稳定且功能完整的,而2.x版专注于Scala,尚不具备1.2.4的所有功能。

You don't have to create a servlet. 您不必创建servlet。 But, you need something that can parse a jsp page - it could be tomcat or some other server which has the same capabilities as tomcat. 但是,您需要可以解析jsp页面的东西-可能是tomcat或其他具有与tomcat功能相同的服务器。 Though I am not sure if I understood your question correctly. 尽管我不确定我是否正确理解了您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM