ASP直接生成html的代码
此方法可以不需要专门制作模板文件,只需正常运行的动态页面即可,具体方法如下,最终使用见最后一个函数:
Function getHTTPPage(url) ‘首页生成开始
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Function CreateStatic(txtURL,FileName)
sText = getHTTPPage(txtURL)
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set openFile=FileObject.OpenTextfile(server.mapPath(Filename),2,true) ‘true为不存在自行建立
openFile.writeline(sText)
Set OpenFile=nothing
End Function
Function CreateIndex()
Response.Write("首页生成中,请稍后...")
Response.Flush()
TxtUrl = "http://"&Request.ServerVariables("SERVER_NAME")&"/Default.asp"
FilePath = "/Default.html"
Call CreateStatic(TxtUrl,FilePath)
Response.Write(" ")
End Function
相关文档:
HTML部分:
<asp:Chart ID="ChartBar" runat="server" Width="800px" BackColor="#FFFFCC" Palette="BrightPastel" BorderWidth = "2" BorderColor = "#cc9900" >
& ......
<%
'true=是邮件;false=不是;
Function validate(ByVal str)
Dim temp,reg
Set reg = new regexp
reg.ignorecase=true
reg.global=true
reg.pattern = "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
validate = reg.test(Trim(str))
Set reg = Nothing
End Function
'************************ ......
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace W ......
public void Gridview_BindNoRecords(GridView gridView, DataTable dt) // gridView,绑定数据源DT
{
int a = dt.Rows.Count;
if (dt.Rows.Count == 0)
& ......