XML and JSP Interaction Technology (3)

Source: Internet
Author: User
Tags object hash key version
js|xml| interaction

Saxpser.parse (XmlFile, handler);

After parsing, use the Handler.gettable () method to return a hash table with data saved

Hashtable hshtable = handler.gettable ();

FILE://uses the collection enumeration to get all the key values in the hash table hshtable

Enumeration Enum=hshtable.keys ();

Object obj;

while (Enum.hasmoreelements ()) {

file://the next element object in the collection

Obj=enum.nextelement ();

Output to JSP page via JSP's built-in object out

The File://hshTable.get () method is used to get the corresponding value based on the key obj.

Out.println ("
"+obj+" = = "+ (String) hshtable.get (obj));

}

}

catch (Saxexception e) {

file://If there is an error, print error details

E.printstacktrace ();

}

%>

The code is well written, put this file in the Web application directory, and then run the program through the browser, such as http://192.168.0.98:7070/welcome_html/jspxml.jsp?file=e:\\ Personal.xml, note that you must use parameters? file= path \\personal.xml (the path is based on the directory you save on your hard disk, Java says: "\ \" is a "\" on the Windows system), and the effect is as follows:

As you can see, all the data in the XML file is read through this JSP file, because the JSP program is file-independent, you can also change the XML file name in File=e:\\personal.xml to other XML files to see the last run effect.

To illustrate the point is that I actually adopted the JAXP1.01 version of the API, there may be my system reasons, the Discovery program in version 1.1 can be compiled, but the runtime will be the following error (even if the JAXP1.1 package with the example of the Main.java also):

Java.lang.NoClassDefFoundError:org.apache.crimson.jaxp.SAXParserFactoryImpl

So finally the 1.01 version of JAXP is used to run the program, and the 1.01 version of JAXP can also be downloaded at the address above.

< personal files >

< name > Liu Yufeng

< sex > Male

< age >24

Coolknight@263.net

< personal homepage >http://www.21jsp.com

< introduction > Welcome to visit my homepage!



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.