Typical Example of JSP writing XML files

Source: Internet
Author: User

// -- Test. jsp is saved in the root directory of Tomcat --
<% @ Page Language = "Java" contenttype = "text/html; charset = gb2312" Import = "Java. util. *, Java. io. * "pageencoding =" gb2312 "%> <%
String item_url = request. getparameter ("item_url"); If (item_url = NULL) item_url = "http: IP // XX. FLV ";
Stringbuilder strxml = new stringbuilder ("<? XML version = '1. 0' encoding = 'utf-8'?> ");
Strxml. append ("<vcaster> ");
Strxml. append ("<item item_url = '" + item_url + "'/> ");
Strxml. append ("</vcaster> ");
// Out. Print (strxml );
Try {
String xml = new string (strxml );
String Path = request. getrealpath ("."); // obtain the current folder path
Filewriter fw = new filewriter (path + "// itemurl. xml"); // create a filewriter object and instantiate the FW
// Write a string to a file
FW. Write (XML, 0, XML. Length (); // write the XML document to the itemurl. xml file.
Out. Print ("<p> the XML file has been saved in the current folder !! </P> ");
Out. Print ("<p> file name: itemurl. xml </P> ");
Out. Print ("<p> item_url:" + item_url + "</P> ");
FW. Close ();
}
Catch (ioexception E)
{
Out. Print ("failed to add XML file ");
}
%>

Note:CodeI have successfully tested Tomcat and implemented dynamic URL value transfer as required. For example, you can enter the following in the IE address bar:
Http: // localhost: 8080/test. jsp? Item_url = www.baidu.com

 

 

This article from: http://zhidao.baidu.com/question/40186033.html thanks to the respondent:Gyhcom-Level 3 Assistant 11-28

!

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.