标记基于Java的搜索引擎英文翻译

英文搜索引擎  时间:2021-04-21  阅读:()

职场大变样社区www. z cdby. com下载毕业设计成品全套资料全部50元以下

学校代码 学 号

二○○八年六月

内蒙古工业大学本科毕业设计外文文献翻译

Dynamic Web-based data access using JSP and JDBCtechnologie s

This article discusses using the JSP and JDBC technologies to integrate static,dynamic,and database content in Web sites.For the purposes of simplicity and illustration,the JSP pages here use short scriptlets to expose the JSP developer to the underlying JDBCconcepts instead of hiding them in custom tags. The author introduces a key designapproach that integrates JavaBeans components with JDBC, similar to the way thatJavaServer Pages technology already uses beans with HTTP.He also provides code forimp lementing this integration.

Building on the Java Servlet technologcore server-side Java architecture for generating dynamic content.One source of dynamiccontent is the relational database. To manage everything from online communities toe-commerce transactions,Web sites use relational databases to store all sorts ofinformation: catalog items, images, text,data about registered members, and so on.Thisarticle discusses the application of JSP technology to relational databases through JavaDatabase Connectivity(JDBC). JDBC is the means by which Java programs work withrelational databases.

To get the most out of this article,you should be familiar with JDBC and SQL.

JDBC basics

JDBC is the bridge between Java code and SQL databases.The primary JDBC objectsrepresent connections to a database and the statements performed using those connections.The two basic kinds of statements used with a relational database are queries and updates.As a prerequisite to each,you first need to establish a connection to the database,which isdone with the j ava.sql.DriverManager class.Connections take a long time(in computertime) to establish, so in a transaction-intensive environment like a Web server,you want toreuse connections whenever possible.Such reuse is called connection pooling.

In real life, JDBC code is not this simple; exceptions and warning conditions need tobe handled. Listing 2 illustrates the same JDBC example but adds handling for JDBCexceptions and warnings. In this example, exceptions and warnings are simply logged and,in the case of exceptions,we abort the operation.However, the f inally{ } clauses ensurethat resource cleanup proceeds.

1

内蒙古工业大学本科毕业设计外文文献翻译

The actual processing of the results is only hinted at here;we'll be looking at it moreclosely later on in this article. If we were performing a database update instead of a query,we would replace the whi le loop with the following:int count = statement.executeUpdate(sqlUpdate) ;

The executeUpdate( )method returns the number of rows affected by the updatestate me nt.

If the material in these code listings seems unfamiliar,you may want to spend sometime reviewing some of the JDBC tutorial information found in the Resources section.

Using JDBC with JSP pages

So how do we combine JDBC and JSP technologies so that our dynamic contentcomes from a database?

As a general rule, good JSP practice suggests that you separate presentation frommodel behavior. This is analogous to the Model-View-Controller (MVC) paradigm inobject-oriented programming.One reason for the separation is that applications based onJSP technology are likely to have the Model and Controller components authored byprogrammers,whereas the View components will be authored by page designers. In thecase of JSP application architectures, the role of View,whose responsibility is presentation,is handled by a JSP page. The role of Controller,whose responsibility is reacting torequests, is often played by a servlet,but many JSP practitioners are coming to realize theadvantages of using a JSP page in the Controller role. The role of Model,whoseresponsibility is modeling the behavior of application entities, is typically played byJavaBeans components.

In addition to deciding where in the MVC paradigm to interact with the database,youhave several choices for integrating JDBC technology into your JSP pages.For example,you can insert JDBC using scriptlets, insert it using a tag library,or hide it within customtags or other classes.We'll next look at examples of several approaches and discuss theiruse.

A tag l ibrary example using DBTags

One of the first things that a new JSP programmer hears, usually fromwell-intentioned friends and experts, is not to use scriptlets. Instead, they tell the new JSPprogrammer to use custom tags.Custom tags are a means by which the JSP platform's

2

内蒙古工业大学本科毕业设计外文文献翻译

capabilities are extended: custom XML-style tags, tied to code libraries, implement thedesired functionality.We'll see how well they work, in our next example.

The Jakarta TagLibs Project is a subproject of the Jakarta Project, the officialreference implementation of the Java Servlet and JavaServer Pages technologies.

One of the packages developed under the auspices of the Jakarta TagLibs Project isthe DBTags custom tag library(formerly known as the JDBC tag library).The JSP page inListing 4 implements the same hit counter as in Listing 3, replacing the scriptlet withcus to m ta gs.

Most tag libraries written to date have been written by programmers for programmers;the semantics of those tags are geared toward other programmers.Furthermore, rememberthe separation of model and presentation?That isn't well supported by DBTags. Thesql:getColumn tag is analogous to the j sp:getProperty action: it emits the tag's resultdirectly into the output stream.That makes it difficult to separate using DBTags fromrendering output into the desired form.Finally,notice that the logic differs between Listing3 and Listing 4.The DBTags execute tag consumes the update count from any updatestatement sent via JDBC;only query results can be retrieved.That means we cannot findout how many rows were updated by the update statement. So we have to switch theupdate and insert statements;we always try to insert a new record, force DBTags toignore any error,and then perform the update.

In fairness to the DBTags tag library, it is not a bad tag library for programmers.Aside from its consumption of the update count, the code provides a fairly good mappingto JDBC.Therein lies the problem, however: the tags provide little more than a directtranslation of the JDBC package.Other than hiding some exception handling, the taglibrary doesn't really provide any abstraction over scriptlets. It certainly doesn't helpseparate p resentatio n fro m functio n.

So, the real issue is not whether to use scriptlets or tags; that question is aconsequence,not a cause, of the problem of separating function from presentation.Thesolution is to provide higher-level functionality to presentation-page authors at anappropriate level of discourse.The reason tags are considered better than scriptlets is thatscriptlets,by definition,are programming,whereas tags can represent high-level concepts.

Hiding JDBC from presentation pages

3

内蒙古工业大学本科毕业设计外文文献翻译

When integrating JDBC with JSP technology,we want to hide as much of thatintegration from the presentation author as possible.Where we do expose databaseconcepts,we want to expose them at a suitable level of abstraction.This approach leads toour next example.

In the example in Listing 5,we hide the JDBC integration from the presentation page.(A live version of this page is located on the JavaServer Pages Developers Guide Web site.)

Integrating with JavaBeans components

The examples so far have been fairly simple,but most database operations are goingto be more sophisticated than these simple queries and updates.So now that we've coveredsome basic principles of using JDBC with JSP pages, let's conclude with a slightly morecomplex,and certainly more common, type of application.

The example for this section will show one way to support visitor-supplied content ona Web site. In other words,we want to allow visitors to read database content associatedwith a URI and to contribute additional content.Such content is fairly common on modernWeb sites.The same basic parts can be used to construct:

Reviewpages, suchas those found on Amazon.com

Links pages

Bulletin boards

W ik iweb s

An only slightly more elaborate version of the JSP components in this example canimplement Web pages that seem very different,authored by designers of varying technicalbackgrounds.All that the pages would appear to have in common is a provision forvis itor-contributed content.

Our annotation example uses an HTML form.When using HTML forms with JSP, itis convenient to use a bean whose properties map to the form fields.

Integration with JavaBeans components is one of the better-designed aspects of JSPtechnology.Unfortunately, the integration between beans and JDBC is not seamless at all,so for our JDBC work at DevTech,we developed a package that provides not onlyintegration between beans and JDBC but also the necessary exception handling, relievingthe programmer from having to deal with the details.

The annotation example uses two of the query and update methods from the

4

内蒙古工业大学本科毕业设计外文文献翻译

com.devtech.sql package.The particular query method used passes a bean class,an SQLquery, and an Obj ect array to fill in the placeholders in the query. In this case, the onlyplaceholder is for the page's URL. The result is a database cursor object,which isessentially a type of iterator.

Integration with JavaBeans components is one of the better-designed aspects of JSPtechnology.Unfortunately, the integration between beans and JDBC is not seamless at all,so for our JDBC work at DevTech,we developed a package that provides not onlyintegration between beans and JDBC but also the necessary exception handling, relievingthe programmer from having to deal with the details.

The annotation example uses two of the query and update methods from thecom.devtech.sql package.The particular query method used passes a bean class,an SQLquery, and an Obj ect array to fill in the placeholders in the query. In this case, the onlyplaceholder is for the page's URL. The result is a database cursor object,which isessentially a type of iterator.

We've used scriptlets in this example only to show you, a programmer,what ishappening. If they were replaced with declarative tags, they would be clear to the pagedes igner,but uninformative to you.

The logic is straightforward. The annotation.getCursor( ) call acquires aconnection to the server, issues the query, and sets up a database cursor object,annotations, on the result set.Each time annotations.next( ) is called, a new row isfetched from the result set,and its values moved into a bean whose reference is returnedfrom the method. The particular next( )method being used takes a bean parameter topopulate.Although we could have the cursor instantiate a new bean for each row, reusingthe bean is more efficient.

Notice that neither the actual query,nor the update, is present in the presentation page.The included page,which sets up the environment for the presentation page,also includesthe setProperty and update actions.Those actions are independent of the presentationpage;only the contract embodied by the annotation bean's properties is significant.Thisis in keeping with a policy to separate presentation from model behavior. The pagedesigner is fully able to change how the presentation is rendered but has no access to howthe database is integrated. If a change is to be effected in updating or querying the database,

5

内蒙古工业大学本科毕业设计外文文献翻译

it is delegated to a JSP programmer.

Summary

This concludes an introduction to combining the JavaServer Pages, JavaBeans, andJDBC technologies to generate dynamic content through relational databases.We startedwith the most obvious approach for the new JSP programmer: scriptlets.We saw how theuncontrolled use of scriptlets intertwines logic and presentation,making both of them hardto maintain.We also saw that tag libraries don't necessarily improve MVC separation,andthat the pages using them may not be understandable to page designers if the tags areexpressed in programming terms. Finally,we looked at more complex examples thatillustrate a few ways to separate database access from the presentation of content.

You should now have some basic ideas about how to integrate database content into aWeb site while hiding the actual database access from page designers.Note, too, that theleast informative examples for you,a programmer,are the ones most appropriate for a pagedesigner.When you plan your JSP solutions,keep your page designers in mi

6

内蒙古工业大学本科毕业设计外文文献翻译

使用J SP和JDB C技术访问基于Web的动态数据

本文讨论使用JSP和JD BC技术把静态的、动态的及数据库内容集成在Web站点中。为了简洁明了的说明问题文中的JSP页面使用短的scriptlet让JSP开发者接触到底层的JDBC概念而不是把其隐藏在定制标记中。作者介绍一种集成JavaBeans组件和JDBC的主要设计方法该方法同一直以来JavaServer Pages技术采用的、把bean用于HTTP的方式类似。他还提供实现该集成的代码。请在讨论论坛同作者及其它读者分享对本文的理解。

JavaServer Page JSP技术建立在Java Servlet技术的基础之上是核心的生成动态内容的服务器端Java体系结构。关系数据库是动态内容的来源之一。Web站点使用关系数据库存储各类信息 目录项、 图像、文本、关于注册成员的资料等等从而管理从在线社区到电子商务交易的一切事务。本文讨论通过Java数据库连接

JD BC把JS P技术应用于关系数据库。正是JDBC使Java程序可以使用关系数据库。

要深入理解本文您应该熟悉JDBC和SQL。

JD B C基础知识

JDBC是Java代码和S Q L数据库之间的一座桥梁。主要的JDBC对象表示同数据库的连接及利用这些连接执行的语句。用于关系数据库的两种基本语句是查询和更新。两者都需要的一个前提条件就是您首先要利用java.sql.DriverM anager类同数据库建立连接。建立连接要花很长时间就计算机时间而言 因此在Web服务器这种事务繁忙的环境中您希望尽可能重用连接。这样的重用叫做建立连接池。

在现实生活中 JD B C代码不会如此简单 因为需要处理异常和警告情况。 清单2说明的是同一个JDBC示例但添加了对JDBC异常和警告的处理。在这个示例中异常和警告只记入日志并且对于异常情况我们将异常终止操作。不过finally{}子句将确保资源清除过程进行。

对真实的结果处理过程在此仅作一下提示我们将在本文后面的部分接着更仔细的分析这个问题。如果我们正在执行的不是数据库查询而是更新那我们可以把while循环替换成如下语句int c o unt=sta te me nt.e xe c uteUp da te(s q lUp date);exec uteUp d ate()方法返回up date语句所作用的行的总数。

如果这些代码清单中的材料显得陌生您也许希望花些时间重温一下在参考资

7

内蒙古工业大学本科毕业设计外文文献翻译

料部分中找到的一些JD B C教程信息。

JDBC用于JSP页面

那么我们怎样结合使用JDBC和JSP技术才能使我们的动态内容来自数据库呢

作为一条普遍的法则 良好的JSP惯例建议您应当把表示同模式行为分离。这与面向对象编程中的“模式-视图-控制器MVC ”范例类似。分离原因之一是基于JSP技术的应用很可能由程序员编写“模式Mode l ”和“控制器Contro ller ”组件而由页面设计人员编写“视图(View)”组件。就JSP应用体系结构而言负责表示的“视图”角色由JSP页面处理。负责对请求做出响应的“控制器”的角色通常由 servlet担当但许多JSP用户开始认识到用JSP页面来担任“控制器”的角色的优点。 “模式”这一角色负责为应用实体的行为构建模式典型情况下由JavaBean组件来担当。

除确定在MVC范例中的何处同数据库交互之外关于在JS P页面中集成JDBC技术您有多种选择。例如您可以使用scrip tlet插入JDBC或使用标记库插入还可以把它隐藏在定制标记或其它的类里。接下来我们要看看一些方式的示例并讨论其用法。

使用DBTag的标记库示例

通常善意的朋友和专家会告诉JSP程序员新手一些基本知识其中之一就是不要使用scriptlet。相反他们会让JSP程序员新手使用定制标记。我们利用定制标记扩展JSP平台的功能 同代码库相连的定制XML样式标记实现预期功能。我们将会在下个示例中看到DB Ta g的工作情况。

Jakarta TagLib s Proje ct是Jakarta P rojec t 请参阅参考资料的一个子工程该工程是Java Servlet和JavaServer Pages技术的官方参考实现。

在Jakarta TagLibs Project的支持下开发的一个包是DBTag定制标记库以前叫做JDBC标记库 。清单4里的JSP页面把scriptlet替换成定制标记实现的点击计数器和清单3中的一模一样。

关于标记库Alla ire没有告诉您的是 标记设计是一种语言设计。迄今为止所写的大多数标记库是由程序员为程序员写的这些标记的语义适合于其它的程序员。不仅如此还记得模式和表示的分离吗 DB Ta g对这一点不太支持。sql:getCo lumn标记同j sp:getP roperty动作类似它把标记的结果直接发给输出流。这给DB Ta g的利用与把输出转化成要求的格式之间的分离带来了困难。最后请注意清单3和清单4的逻辑差异。DB Ta g的e xec ute标记使用所有来自通过JDBC

8

新版本Apache HTTP Server 2.4.51发布更新(有安全漏洞建议升级)

今天中午的时候看到群里网友在讨论新版本的Apache HTTP Server 2.4.51发布且建议更新升级,如果有服务器在使用较早版本的话可能需要升级安全,这次的版本中涉及到安全漏洞的问题。Apache HTTP 中2.4.50的修复补丁CVE-2021-41773 修复不完整,导致新的漏洞CVE-2021-42013。攻击者可以使用由类似别名的指令配置将URL映射到目录外的文件的遍历攻击。这里...

HostYun(25元)俄罗斯CN2广播IP地址

从介绍看啊,新增的HostYun 俄罗斯机房采用的是双向CN2线路,其他的像香港和日本机房,均为国内直连线路,访问质量不错。HostYun商家通用九折优惠码:HostYun内存CPUSSD流量带宽价格(原价)购买地址1G1核10G300G/月200M28元/月购买链接1G1核10G500G/月200M38元/月购买链接1G1核20G900G/月200M68元/月购买链接2G1核30G1500G/月...

香港云服务器 1核 1G 29元/月 快云科技

快云科技: 12.12特惠推出全场VPS 7折购 续费同价 年付仅不到五折公司介绍:快云科技是成立于2020年的新进主机商,持有IDC/ICP等证件资质齐全主营产品有:香港弹性云服务器,美国vps和日本vps,香港物理机,国内高防物理机以及美国日本高防物理机产品特色:全配置均20M带宽,架构采用KVM虚拟化技术,全盘SSD硬盘,RAID10阵列, 国内回程三网CN2 GIA,平均延迟50ms以下。...

英文搜索引擎为你推荐
画风不同神情相同的各种systemsnod32版本itunes支持ipadwin7关闭445端口如何快速关闭445端口windows键是哪个windows 快捷键 大全iphone连不上wifi苹果8p连接不了WiFi127.0.0.1DNS老是被修改为127.0.0.1,这是为什么?ms17-010win1038度古贝春珍藏10价格?联通版iphone4s联通版iPhone4s 用联通3G卡好还是移动的好
联通vps 日本软银 enzu inmotionhosting 美国主机推荐 linode代购 韩国加速器 l5520 php探针 线路工具 个人免费空间 150邮箱 anylink 免费美国空间 彩虹云 万网空间管理 独立主机 lamp架构 双线空间 国外免费云空间 更多