ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:25.48KB ,
资源ID:7216309      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7216309.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(计算机专业文献翻译XML与JSP联手.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

计算机专业文献翻译XML与JSP联手.docx

1、计算机专业文献翻译XML与JSP联手英文原文: Using XML and JSP together Im going to assume that, like most Java programmers, you know what JavaServer Pages (JSP) and Extensible Markup Language (XML) are, but you may be a little unclear on how you can use them. JSP use is pretty easy to defend. It allows you to design a

2、Website built from files that look and act a lot like HTML. The only difference is that JSPs also act dynamically - for example, they can process forms or read databases - using Java as a server-side scripting language. XML use is more difficult to justify. While it seems as if every new product sup

3、ports it, each one seems to be using XML for a different purpose.In this article, you will learn to design a system using XML in a fairly modest way. Many Websites have vast collections of data that are displayed in a more or less standard way. I will design a system that uses XML files to store dat

4、a on a Web server and JSP files to display that data. XML versus relational databases But wait, you may ask, youre using XML to store data? Why not use a database? Good question. The answer is that for many purposes, a database is overkill. To use a database, you have to install and support a separa

5、te server process, which often also requires installing and supporting a database administrator. You must learn SQL, and write SQL queries that convert data from a relational to an object structure and back again. If you store your data as XML files, you lose the overhead of an extra server. You als

6、o gain an easy way to edit your data: just use a text editor, rather than a complicated database tool. XML files are also easier to back up, to share with your friends, or to download to your clients. You can also easily upload new data to your site, using FTP. A more abstract advantage of XML is th

7、at, being a hierarchical rather than a relational format, it can be used in a much more straightforward manner to design data structures that fit your needs. You dont need to use an entity relationship editor nor normalize your schema. If you have one element that contains another element, you can r

8、epresent that directly in the format, rather than using a join table. Note that for many applications, a filesystem will not suffice. If you have a high volume of updates, a filesystem may get confused or corrupted by simultaneous writes; databases usually support transactions, which allow concurren

9、cy without corruption. Further, a database is an excellent tool if you need to make complicated queries, especially if they will vary from time to time. Databases build indexes, and are optimized for keeping the indexes up to date with a constantly changing data set. Relational databases also have m

10、any other advantages, including a rich query language, mature authoring and schema design tools, proven scalability, fine-grained access control, and so on. (Note: You can use simple file locking to provide a poor mans transaction server. And you can also implement an XML index-and-search tool in Ja

11、va, but thats a topic for another article.) In this case, as in most low-to-medium volume, publishing-based Websites, you can assume the following: most of the data access is reads, not writes; the data, though potentially large, is relatively unchanging; you wont need to do complicated searches, bu

12、t if you do, youll use a separate search engine. The advantages of using a mature RDBMS fade, while the advantage of using an object-oriented data model come to the fore. Finally, its entirely possible to provide a wrapper for your database that makes SQL queries and translates them into XML streams

13、, so you could have it both ways. XML becomes a more robust, programmer-friendly frontend to a mature database for storing and searching. (Oracles XSQL servlet is one example of this technique.) The application: An online photo album Everybody loves photos! People love showing pictures of themselves

14、, their friends, their pets, and their vacations. The Web is the ultimate medium for self-indulgent shutterbugs - they can annoy their relatives from thousands of miles away. While a full-fledged photo album site would require a complicated object model, Ill focus on defining a single Picture object

15、. (The source code for this application is available in Resources.) The object representing a picture needs fields representing its title, the date it was taken, an optional caption, and, obviously, a pointer to the image source. An image, in turn, needs a few fields of its own: the location of the

16、source file (a GIF or JPEG) and the height and width in pixels (to assist you in building tags). Here there is one neat advantage to using the filesystem as your database: you can store the image files in the same directory as the data files. Finally, lets extend the picture record with an element d

17、efining a set of thumbnail images for use in the table of contents or elsewhere. Here I use the same concept of image I defined earlier. The XML representation of a picture could look something like this: Alex On The Beach 1999-08-08 Trying in vain to get a tan alex-beach.jpg 340 200 alex-beach-sm.j

18、pg 72 72 alex-beach-med.jpg 150 99 Note that by using XML, you put all the information about a single picture into a single file, rather than scattering it among three or four separate tables. Lets call this a .pix file - so your filesystem might look like this: summer99/alex-beach.pixsummer99/alex-

19、beach.jpgsummer99/alex-beach-sm.jpgsummer99/alex-beach-med.jpgsummer99/alex-snorkeling.pixetc.Techniques Theres more than one way to skin a cat, and theres more than one way to bring XML data on to your JSP page. Here is a list of some of those ways. (This list is not exhaustive; many other products

20、 and frameworks would serve equally well.) DOM: You can use classes implementing the DOM interface to parse and inspect the XML file XMLEntryList: You can use my code to load the XML into a java.util.List of name-value pairs XPath: You can use an XPath processor (like Resin) to locate elements in th

21、e XML file by path name XSL: You can use an XSL processor to transform the XML into HTML Cocoon: You can use the open source Cocoon framework Roll your own bean: You can write a wrapper class that uses one of the other techniques to load the data into a custom JavaBean Note that these techniques cou

22、ld be applied equally well to an XML stream you receive from another source, such as a client or an application server. JavaServer Pages The JSP spec has had many incarnations, and different JSP products implement different, incompatible versions of the spec. I will use Tomcat, for the following rea

23、sons: It supports the most up-to-date versions of the JSP and servlet specs Its endorsed by Sun and Apache You can run it standalone without configuring a separate Web server Its open source (For more information on Tomcat, see Resources.) You are welcome to use any JSP engine you like, but configur

24、ing it is up to you! Be sure that the engine supports at least the JSP 1.0 spec; there were many changes between 0.91 and 1.0. The JSWDK (Java Server Web Development Kit) will work just fine. The JSP structure When building a JSP-driven Website (also known as a Webapp), I prefer to put common functi

25、ons, imports, constants, and variable declarations in a separate file called init.jsp, located in the source code for this article. I then load that file into each JSP file using . The directive acts like the C languages #include, pulling in the text of the included file (here, init.jsp) and compili

26、ng it as if it were part of the including file (here, picture.jsp). By contrast, the tag compiles the file as a separate JSP file and embeds a call to it in the compiled JSP. Finding the file When the JSP starts, the first thing it needs to do after initialization is find the XML file you want. How

27、does it know which of the many files you need? The answer is from a CGI parameter. The user will invoke the JSP with the URL picture.jsp?file=summer99/alex-beach.pix (or by passing a file parameter through an HTML form). However, when the JSP receives the parameter, youre still only halfway there. Y

28、ou still need to know where on the filesystem the root directory lies. For example, on a Unix system, the actual file may be in the directory /home/alex/public_html/pictures/summer99/alex-beach.pix. JSPs do not have a concept of a current directory while executing, so you need to provide an absolute

29、 pathname to the java.io package. The Servlet API provides a method to turn a URL path, relative to the current JSP or Servlet, into an absolute filesystem path. The method ServletContext.getRealPath(String) does the trick. Every JSP has a ServletContext object called application, so the code would

30、be: String picturefile = application.getRealPath(/ + request.getParameter(file);or String picturefile = getServletContext().getRealPath(/ + request.getParameter(file);which also works inside a servlet. (You must append a / because the method expects to be passed the results of request.getPathInfo().

31、) One important note: whenever you access local resources, be very careful to validate the incoming data. A hacker, or a careless user, can send bogus data to hack your site. For instance, consider what would happen if the value file=././././etc/passwd were entered. The user could in this way read your servers password file. The Document Object Model DOM stands for the Document Object Model. It is a standard API for browsing XML documents, developed by the World

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1