Combination of XML and JSP (2)

Source: Internet
Author: User

Application: an online album


Everyone enjoys photography! They like to show photos of their loved ones, friends, and vacations, while web is a good place for them. -- Even if you are a relative of a thousand miles away, you can see it. I will focus on defining a separate picture object. (The source code of this application can be obtained in resources ). This object describes the fields required for a photo: title, date, an optional title, and a point to the image source.

An image requires some of its own fields: location, width, and height of the source file (gif/jpeg) pixels (to assist in the creation of the mark. Here we can see a very simple advantage, that is, when you use a file system to replace the database, you can store graphical files in the same directory as the data files.

Finally, let's extend the image record with an element that defines a set of thumbnails (thumbnail) for content tables or other places. Here I used the same image content as previously defined.

The xml Representation of an image can be as follows:

<Picture>
<Title> alex on the beach </title>
<Date> </date>
<Caption> trying in vain to get a tan </caption>
<Image>
<Src> alex-beach.jpg </src>
<Width> 340 </width>
<Height> 200 </Image>
<Thumbnails>
<Image>
<Src> alex-beach-sm.jpg </src>
<Width> 72 </width>
<Height> 72 </Image>
<Image>
<Src> alex-beach-med.jpg </src>
<Width> 150 </width>
<Height> 99 </Image>
</Thumbnails>
</Picture>


Note: By using xml, you can store all the information of a single image in a separate file instead of distributing it into 3-4 tables.
We call this. pix file

-- So your file system will be like this:

Summer99/ alex-beach.pix
Summer99/ alex-beach.jpg
Summer99/ alex-beach-sm.jpg
Summer99/ alex-beach-med.jpg
Summer99/ alex-snorkeling.pix
Etc.

Technology

As the saying goes, there is only one way to peel off a cat's skin. Similarly, there are more than one way to put xml data into jsp. Some of the methods are listed here (in fact, many other tools can do the same well .)

Dom: You can use a class (classes) to call the dom interface to analyze and check xml files.
Xmlentrylist: You can use my code to load xml to java. util. list of name-value pairs.

Xpath: You can use an xpath processor (such as resin) to locate elements in an xml file by path name.

Xsl: You can use an xsl processor to convert xml into html.

Cocoon: You can use the open-source cocoon framework.

Run your own bean: you can write a wrapper class and use some other technology to load data into the word-defined javabean.


Note that these technologies will be executed equally well with an xml stream you obtained from another source, such as a client or an application server.

Assumerver pages


Jsp specifications have many substitutes. Different jsp products have different performance and different versions have different performance. I chose tomcat for the following reasons:
It supports most of the latest jsp/servlet specifications
It is recognized by sun and apache
You can run it independently without configuring another web server.
It is open source

You can choose any jsp Engine you like, but to configure it yourself, it must support at least the jsp 1.0 specification. There are many differences between 0.91 and 1.0. The jswdk (java server web development kit) may have just been well suited to requirements.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.