使用 Servlet 和 HTML [英] Using Servlets and HTML

查看:26
本文介绍了使用 Servlet 和 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 servlet 的使用有疑问.

I have a doubt regarding the use of servlets.

在我正在构建的应用程序中,我使用 Html 页面向用户询问信息.

In the application I'm building I use Html pages to ask the user for info.

想象一个 Html 页面,让用户请求在屏幕上查看数据库的内容.我正在做的是:

Imagine a Html page that lets the user request to see on the screen the content of a data base. What I'm doing is:

1.- 从 Html 页面,我正在调用一个 servlet,它将打开与数据库的连接.2.- servlet 构建用户将看到的网页.

1.- From the Html page I'm calling a servlet that will open a connection with the database. 2.- The servlet builds the web page that the user will see.

我的问题是:有没有其他方法可以做到这一点?我是否必须在 servlet 中构建网页,或者是否有任何方法可以将数据库中包含的信息发送到将构建网页的 .html 文件(在我的情况下,我需要在屏幕上显示一个包含所有信息)?

My question is: is there any other way of doing this? Do I have to build the web page in the servlet or is there any way of sending the information contained in the database to an .html file which will build the web page (in my case I need to show on the screen a table containing all the information) ?

谢谢

推荐答案

最终浏览器必须向服务器发送数据库信息请求.您可以通过多种方式执行此操作:

Ultimately the browser has to send a request to the server for the database info. You can do this in many ways:

  1. 在 servlet 中构建整个页面(也许是最简单的)
  2. 在 servlet 中构建一个包含(比如)XML 数据的页面,浏览器将其呈现为 HTML(通过 XSL/Javascript 等).如果您希望浏览器控制格式和演示,这可能是合适的.
  3. 构建一个包含 AJAX 请求的页面,以返回服务器并获取数据.这可能更适合定期更新的数据或更互动性更强的应用.

有很多方法可以给这只猫剥皮.我怀疑你在做最简单的一个,这很好.我倾向于在没有明确要求的情况下做到这一点,这意味着我需要做其他事情.使问题复杂化的进一步要求可能包括分页数据,如果有太多内容无法显示在屏幕上.以上所有解决方案都可以以某种方式结合这一点.

There are numerous ways to skin this cat. I suspect you're doing the simplest one, which is fine. I would tend towards this without explicit requirements that mean I need to do something else. Further requirements that complicate matters may include paging the data if there's too much to fit on the screen. All the solutions above can be made to incorporate this in some fashion.

这篇关于使用 Servlet 和 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆