// -- 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
!