如何从jsp页面生成的输出中创建特定位置的xml文件

时间:2021-07-16 09:54:51

sports.jsp:

<?xml version="1.0" encoding="UTF-8"?>

<%@ page contentType="text/xml;charset=ISO-8859-1" %>
<% response.setHeader("Content-Disposition", "attachment; filename=\"playlist.xml\""); %>
<playlist version="1" xmlns = "http://xspf.org/ns/0/">
   <title>My Band Rocks Your Socks</title>
   <trackList>
   <%! String[] sports; %>
   <%
      sports = request.getParameterValues("sports");
      if (sports != null)
      {
         for (int i = 0; i < sports.length; i++)
         {
            // out.println (sports[i]);
            String total=sports[i];
            String[] sa=total.split("[,]");
            // String[] sub=new String();
            out.print("<track>");
            for (int j=0;j<sa.length;j++)
            {
               // out.println(sa[j]);
               // out.println("sa["+j+"]="+sa[j]);
               if( j == 0)
               {
                  out.print("<location>" + sa[0] +"</location>");
               }
               else if (j == 1)
               {
                  out.print("<image>" + sa[1] +"</image>");
               }
               else if( j==2)
               {
                  out.print("<title>" + sa[2] +"</title>");
               }
            }// end of inner for loop()
            out.print("</track>");
            //out.println();
         }// end of outer for()
      }
      //else out.println ("<b>none<b>");
   %>
   </trackList>
</playlist>

This code is generating an xml file, but it is prompting me to mention the location where to save it.I want to create and store xml file at a particular location without any prompting and each time for the next input values the current xml file should be overwritten.

这段代码生成了一个xml文件,但是它提示我提一下保存它的位置。我想在没有任何提示的情况下在特定位置创建和存储xml文件,每次下一个输入值时,当前的xml文件都应该被覆盖。

2 个解决方案

#1


You're asking for a feature that no browser wants to provide, due to security risks. You don't want a browser to be able to overwrite an arbitrary file on the system with no user prompt.

由于存在安全风险,您要求提供无浏览器想要提供的功能。您不希望浏览器在没有用户提示的情况下覆盖系统上的任意文件。

If you really need to do this, you need to be running a signed Applet or Web Start application. With this, you have permission to write locally without a user prompt. If you don't want to purchase an official certificate, you can use a self-signed certificate to sign your JAR files. If you do this, the user will get a prompt when they encounter your application about the certificate. However, once the Applet/Web Start application is running, you have free reign to write locally.

如果您确实需要这样做,则需要运行已签名的Applet或Web Start应用程序。有了这个,您有权在没有用户提示的情况下在本地编写。如果您不想购买官方证书,可以使用自签名证书对JAR文件进行签名。如果执行此操作,用户将在遇到有关证书的应用程序时收到提示。但是,一旦Applet / Web Start应用程序运行,您就可以在本地*编写。

Note: You need to edit your question to insert four blanks in front of each line of your JSP, so it will be correctly and automatically formatted by *.

注意:您需要编辑问题以在JSP的每一行前面插入四个空格,以便*正确地自动格式化它。

#2


You cannot do that due to security restrictions. You cannot get access of user system and start writing files without user's permission.

由于安全限制,您无法做到这一点。未经用户许可,您无法访问用户系统并开始编写文件。

#1


You're asking for a feature that no browser wants to provide, due to security risks. You don't want a browser to be able to overwrite an arbitrary file on the system with no user prompt.

由于存在安全风险,您要求提供无浏览器想要提供的功能。您不希望浏览器在没有用户提示的情况下覆盖系统上的任意文件。

If you really need to do this, you need to be running a signed Applet or Web Start application. With this, you have permission to write locally without a user prompt. If you don't want to purchase an official certificate, you can use a self-signed certificate to sign your JAR files. If you do this, the user will get a prompt when they encounter your application about the certificate. However, once the Applet/Web Start application is running, you have free reign to write locally.

如果您确实需要这样做,则需要运行已签名的Applet或Web Start应用程序。有了这个,您有权在没有用户提示的情况下在本地编写。如果您不想购买官方证书,可以使用自签名证书对JAR文件进行签名。如果执行此操作,用户将在遇到有关证书的应用程序时收到提示。但是,一旦Applet / Web Start应用程序运行,您就可以在本地*编写。

Note: You need to edit your question to insert four blanks in front of each line of your JSP, so it will be correctly and automatically formatted by *.

注意:您需要编辑问题以在JSP的每一行前面插入四个空格,以便*正确地自动格式化它。

#2


You cannot do that due to security restrictions. You cannot get access of user system and start writing files without user's permission.

由于安全限制,您无法做到这一点。未经用户许可,您无法访问用户系统并开始编写文件。