经典Asp如何将生成的HTML保存到服务器上的文本文件中?

时间:2022-12-14 00:28:25

Is there a way to save the current page´s HTML content into a text file on server?

有没有办法将当前页面的HTML内容保存到服务器上的文本文件中?

Scenario: I have a classic ASP page that generates HTML(report tables and stuff), after the whole page is generated, I would like to save it´s HTML code into a file on server, so I can read it later.

场景:我有一个生成HTML(报表和内容)的经典ASP页面,在生成整个页面之后,我想将它的HTML代码保存到服务器上的文件中,以便稍后阅读。

1 个解决方案

#1


1  

By replacing response.write by f.write, you can save the file on server instead of sending file to the browser, Where f is createTextFile Object:

通过用f.write替换response.write,可以将文件保存在服务器上,而不是将文件发送到浏览器,其中f是createTextFile对象:

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject") 
set f=fs.CreateTextFile("c:\test.txt",true)
f.write("Your current html and asp codes goes here considering syntax which connects html strings and asp codes in classic asp")
f.close
set f=nothing
set fs=nothing
%>

if you want to save your current page into server by a human action, you can get entire you html content using (javascript) jquery and send it to an ASP file to save it in a file. So you have to add a javascript function and a form which sends the content:

如果你想通过人工操作将当前页面保存到服务器中,你可以使用(javascript)jquery获取整个html内容并将其发送到ASP文件以将其保存在文件中。所以你必须添加一个javascript函数和一个发送内容的表单:

    <html>
    <!--your entire page is here-->
    </html>

    <!--You should add these extra code at the end of html file:-->
    <a onclick="submitform();">Save the page by clicking here</a>

    <form id="myform" action="savefile.asp" method="post">
    <textarea name="body"></textarea>
    </form>

    <script type="text/javascript">
    // assuming you have included jquery in your project:
    function getPageHTML() {
      return "<html>" + $("html").html() + "</html>" // You can also add doctype or other content out of html tags as you need;
    }

    function submitform(){
    var content=getPageHTML();
    $("#mytextarea").val(content);
    $("#myform").submit()
    }
    </script>

and this would be the source of asp page naming savefile.asp :

这将是asp页面命名savefile.asp的来源:

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject") 
set f=fs.CreateTextFile (server.mapath("test.txt"),true)
dim body
body=request.form("body")
body=replace(body,chr(34),chr(34)&chr(34)) 'To escpase double quotes
f.write (body)
f.close
set f=nothing
set fs=nothing
%>

#1


1  

By replacing response.write by f.write, you can save the file on server instead of sending file to the browser, Where f is createTextFile Object:

通过用f.write替换response.write,可以将文件保存在服务器上,而不是将文件发送到浏览器,其中f是createTextFile对象:

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject") 
set f=fs.CreateTextFile("c:\test.txt",true)
f.write("Your current html and asp codes goes here considering syntax which connects html strings and asp codes in classic asp")
f.close
set f=nothing
set fs=nothing
%>

if you want to save your current page into server by a human action, you can get entire you html content using (javascript) jquery and send it to an ASP file to save it in a file. So you have to add a javascript function and a form which sends the content:

如果你想通过人工操作将当前页面保存到服务器中,你可以使用(javascript)jquery获取整个html内容并将其发送到ASP文件以将其保存在文件中。所以你必须添加一个javascript函数和一个发送内容的表单:

    <html>
    <!--your entire page is here-->
    </html>

    <!--You should add these extra code at the end of html file:-->
    <a onclick="submitform();">Save the page by clicking here</a>

    <form id="myform" action="savefile.asp" method="post">
    <textarea name="body"></textarea>
    </form>

    <script type="text/javascript">
    // assuming you have included jquery in your project:
    function getPageHTML() {
      return "<html>" + $("html").html() + "</html>" // You can also add doctype or other content out of html tags as you need;
    }

    function submitform(){
    var content=getPageHTML();
    $("#mytextarea").val(content);
    $("#myform").submit()
    }
    </script>

and this would be the source of asp page naming savefile.asp :

这将是asp页面命名savefile.asp的来源:

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject") 
set f=fs.CreateTextFile (server.mapath("test.txt"),true)
dim body
body=request.form("body")
body=replace(body,chr(34),chr(34)&chr(34)) 'To escpase double quotes
f.write (body)
f.close
set f=nothing
set fs=nothing
%>