asp最简单提交源码_ASP源码

hacker|
173

文章目录:

如何编写asp程序对客户端以get形式提交的数据然后以post方式请求另一个asp页面?

--------------------a.asp----------------------

% aaa=request("aaa") %

form action=b.asp method=post

input type=text name=aaa value=%=aaa %

input type=submit value=提交

/form

--------------------b.asp----------------------

%

aaa=request.form("aaa")

response.write aaa

%

写了个最简单的源码

在浏览器输入http://你的路径/a.asp?aaa=你要传递的变量 试试

ASP中最简单的提交数据

%

'rs.open "user",conn,1,3

'应该改成:

'sql = "select * from user"

'rs.open sql,conn,1,3

'-----数据操作不要直接从表单中获得,先赋值给变量,然后进行字符过滤判断------

user = Trim(request.form("user"))

pass = Trim(request.form("pass"))

name = Trim(request.form("name"))

call = Trim(request.form("call"))

qq = Trim(request.form("qq"))

mail = Trim(request.form("mail"))

IP = request.ServerVariables("REMOTE_HOST")

if user="" or pass="" or name="" or call="" or qq="" or mail="" then

response.write("scriptalert('请填写完整再提!');location.href='guestbookIndex.asp';/script")

response.end()

end if

set conn=server.CreateObject("adodb.connection")

conn.open"provider=Microsoft.jet.oledb.4.0;data source="server.mappath("alien/526813370.mdb")

set rs=server.createobject("adodb.recordset")

sql = "select * from user where user='"user"'" '用户名应该是唯一的,先判断是否存在记录.

rs.open sql,conn,1,3

if rs.eof and rs.bof then

rs.AddNew '新增一条记录

rs("user")=user

rs("pass")=pass

rs("name")=name

rs("call")=call

rs("qq")=qq

rs("mail")=mail

rs("IP")=IP

rs.update '进行实际更新

else

response.write("scriptalert('用户名"user"已经存在!');location.href='guestbookIndex.asp';/script")

response.end()

end if

rs.close

set rs=nothing

conn.close

set conn=nothing

response.write("scriptalert('已经成功保存,单击确定返回到首页!');location.href='guestbookIndex.asp';/script")

%

这里还有个字符安全过滤的过程,给你个过滤函数

Function Repalces(ParaValue)

if ParaValue = "" then

Repalces = ""

exit function

end if

'过虑非法字符

ParaValue = Replace(ParaValue,"'","")

ParaValue = Replace(ParaValue,"""","")

ParaValue = Replace(ParaValue,"select ","")

ParaValue = Replace(ParaValue,"insert ","")

ParaValue = Replace(ParaValue,"delete ","")

ParaValue = Replace(ParaValue,"count\(","")

ParaValue = Replace(ParaValue,"drop table ","")

ParaValue = Replace(ParaValue,"update ","")

ParaValue = Replace(ParaValue,"truncate ","")

ParaValue = Replace(ParaValue,"asc\(","")

ParaValue = Replace(ParaValue,"mid\(","")

ParaValue = Replace(ParaValue,"char\(","")

ParaValue = Replace(ParaValue,"xp_cmdshell","")

ParaValue = Replace(ParaValue,"xp_dirtree","")

ParaValue = Replace(ParaValue,"exec master","")

ParaValue = Replace(ParaValue,"net localgroup administrators","")

ParaValue = Replace(ParaValue," and ","")

ParaValue = Replace(ParaValue,"net user","")

ParaValue = Replace(ParaValue," or ","")

ParaValue = Replace(ParaValue,"system_user","")

ParaValue = Replace(ParaValue,"IS_SRVROLEMEMBER","")

ParaValue = Replace(ParaValue,"db_name\(","")

ParaValue = Replace(ParaValue,"substring\(","")

ParaValue = Trim(ParaValue)

Repalces = ParaValue

End function

求助一个简单的asp程序代码。

script type="text/javascript"

function och(_value)

{

if (_value=="baidu")

{

location.href = "";

}else if(_value=="sohu"){

location.href = "";

}else if(_value=="sina"){

location.href = "";

}

}

/script

div

请选择:

select name="wch" id="wch"

option value="baidu"百度/option

option value="sohu"sohu/option

option value="sina"sina/option

/select

input type="button" name="btn" value="提交" onclick="och(document.getElementById('wch').value);" /

/div

用asp文件更新xml文件的asp源码 要求详细代码! 最简单明白的!谢谢!

下面的希望是你需要的,能给你帮助:

编写Userdata.asp程序来完成XML文件转换,数据的浏览、修改、删除:

%

''-------------------------------------------------------------------

''删除记录函数deleteDetail

''strXMLFile - 要载入的XML文件。

''strXSLFile - 显示XML文件的XSL样式单文件。

''strEMail - 要删除客户的电子邮件。

''-------------------------------------------------------------------

Function deleteDetail(strXMLFile, strXSLFile, strEMail)

Dim objDom

Dim objRoot

Dim objNode

set objXML = Server.CreateObject("Microsoft.XMLDOM")

objXML.async = false

objXML.load strXMLFile

Set objRoot = objXML.documentElement

Set objNode = objRoot.SelectSingleNode("个人资料[field/field_value=''" strEMail "'']")

objRoot.removeChild(objNode)

objXML.save strXMLFile

loadXMLFile strXMLFile,strXSLFile

End Function

''-------------------------------------------------------------------

''更新记录函数updateDetail

''-------------------------------------------------------------------

Function updateDetail(strXMLFile, strXSLFile, strEMail)

''Declare local variables.

Dim objDom

Dim objRoot

Dim objContact

Dim objField

Dim strNewEMail

strNewEMail = Request.Form("电子邮件")

set objXML = Server.CreateObject("Microsoft.XMLDOM")

objXML.async = false

objXML.load strXMLFile

Set objRoot = objXML.documentElement

Set objContact = objRoot.SelectSingleNode("个人资料[field/field_value=''" strEMail "'']")

For each objItem in Request.Form

Set objField = objContact.selectSingleNode("field[@id=''" objItem "'']/field_value")

objField.text = Request.Form(objItem)

Next

objXML.save strXMLFile

viewDetail strXMLFile, strXSLFile, strNewEMail

End Function

''-------------------------------------------------------------------

''显示个人详细资料函数viewDetail

''-------------------------------------------------------------------

Function viewDetail(strXMLFile, strXSLFile, strEMail)

Dim objXML

Dim objNode

Dim objXSL

set objXML = Server.CreateObject("Microsoft.XMLDOM")

objXML.async = false

objXML.load(strXMLFile)

Set objNode = objXML.SelectSingleNode("客户资料表/个人资料[field/field_value=''" strEMail "'']")

set objXSL = Server.CreateObject("Microsoft.XMLDOM")

objXSL.async = false

objXSL.load(strXSLFile)

Response.Write(objNode.transformNode(objXSL))

End Function

''-------------------------------------------------------------------

''显示所有信息函数loadXMLFile

''-------------------------------------------------------------------

Function loadXMLFile(strXMLFile, strXSLFile)

Dim objXML

Dim objXSL

set objXML = Server.CreateObject("Microsoft.XMLDOM")

objXML.async = false

objXML.load(strXMLFile)

set objXSL = Server.CreateObject("Microsoft.XMLDOM")

objXSL.async = false

objXSL.load(strXSLFile)

Response.Write(objXML.transformNode(objXSL))

End Function

Dim strMode

Dim strEMail

strMode = Request.QueryString("mode")

strEMail = Request.QueryString("email")

Select Case strMode

Case "viewdetail"

viewDetail server.MapPath("Userdata.xml"), server.MapPath("viewdetail.xsl"), strEMail

Case "editdetail"

viewDetail server.MapPath("Userdata.xml"), server.MapPath("editdetail.xsl"), strEMail

Case "updatedetail"

updateDetail server.MapPath("Userdata.xml"), server.MapPath("viewdetail.xsl"), strEMail

Case "deletedetail"

deleteDetail server.MapPath("Userdata.xml"), server.MapPath("Userdata.xsl"), strEMail

Case Else

loadXMLFile server.MapPath("Userdata.xml"), server.MapPath("Userdata.xsl")

End Select

%

我们可以利用下面的文件来完成新客户信息的输入,文件addnewdata.htm如下:

htmlheadtitle客户信息输入/title/head

body bgcolor="#0099ff"

form action="processAdd.asp" method="post"

h3请输入您的客户信息/h3

姓名: input type="text" id="姓名" name="姓名"br

性别: input type="text" id="性别" name="性别"br

地址: input type="text" id="地址" name="地址"br

邮政编码: input type="text" id="邮政编码" name="邮政编码"br

电话: input type="text" id="电话" name="电话"br

电子邮件: input type="text" id="电子邮件" name="电子邮件"brbr

input type="submit" id="btnSub" name="btnSub" value="填好了,发送"br

/form

/body

/html

当填写完上面的表单后,提交到数据处理程序processAdd.asp,本程序可以判断Userdata.xml文件是否存在,如果不存在,就建立新文件;否则把提交的数据添加到Userdata.xml中。然后根据提交成功与否,显示数据保存成功与失败。processAdd.asp程序如下:

%

''--------------------------------------------------------------------

''添加数据的函数addNewdatatoXML

''--------------------------------------------------------------------

Function addNewdatatoXML(strFileName)

Dim objDom

Dim objRoot

Dim objRecord

Dim objField

Dim objFieldValue

Dim objattID

Dim objattTabOrder

Dim objPI

Dim blnFileExists

Dim x

Set objDom = server.CreateObject("Microsoft.XMLDOM")

objDom.preserveWhiteSpace = True

blnFileExists = objDom.Load(strFileName)

If blnFileExists = True Then

Set objRoot = objDom.documentElement

Else

Set objRoot = objDom.createElement("客户资料表")

objDom.appendChild objRoot

End If

Set objRecord = objDom.createElement("个人资料")

objRoot.appendChild objRecord

For x = 1 To Request.Form.Count

If instr(1,Request.Form.Key(x),"btn") = 0 Then

Set objField = objDom.createElement("field")

Set objattID = objDom.createAttribute("id")

objattID.Text = Request.Form.Key(x)

objField.setAttributeNode objattID

Set objattTabOrder = objDom.createAttribute("taborder")

objattTabOrder.Text = x

objField.setAttributeNode objattTabOrder

Set objFieldValue = objDom.createElement("field_value")

objFieldValue.Text = Request.Form(x)

objRecord.appendChild objField

objField.appendChild objFieldValue

End If

Next

If blnFileExists = False then

Set objPI = objDom.createProcessingInstruction("xml", "version=''1.0'' encoding=''gb2312''")

objDom.insertBefore objPI, objDom.childNodes(0)

End If

objDom.save strFileName

Set objDom = Nothing

Set objRoot = Nothing

Set objRecord = Nothing

Set objField = Nothing

Set objFieldValue = Nothing

Set objattID = Nothing

Set objattTabOrder = Nothing

Set objPI = Nothing

End Function

On Error Resume Next

addNewdatatoXML server.MapPath("Userdata.xml")

If err.number 0 then

Response.write("htmlbody bgcolor=''#0099ff''centerfont color=redb您提交的表单没有成功保存,请重新提交!!/bbrbra href=''javascript:history.go(-1)''点击这里重新进行提交。/a/body/html")

Else

Response.write("htmlbody bgcolor=''#0099ff''centerfont color=redb您提交的表单已经成功保存!!!/bbrbra href=''Userdata.asp''点击这里查看添加后客户资料?lt;/a/body/html")

End If

%

至此,我们完成对XML文件进行数据添加、浏览、修改、删除的所有工作。以上程序在iis+IE6和Netscape下调试通过。

祝福你,朋友!

求一个用ASP做出来的简单的网页源代码,急!!!!!!

如果user表存在并且设计好。

假设字段分别为id,name,classname

那么如下代码即可。

name=request("name")

classname=request("classname")

set rs=server.createobject("adodb.recordset")

rs.open "select * from user",conn,1,3

rs.addnew

rs("name")=name

rs("classname")=classname

rs.update

rs.close

html的表单部分,用你的那2个文本框来输入就可以了。name和classname可以根据你自己的需要来改名。

多动手,祝你成功。

简单asp上传文件代码

我还是一点一点用一个实例来说明的吧,客户端HTML如下。要浏览上传附件,

我们通过input type="file"元素,但是一定要注意必须设置form的enctype

属性为"multipart/form-data":

form method="post" action="upload.asp"

enctype="multipart/form-data"

label

input type="file" name="file1" /

/label

input type="text" name="filename" value="default filename"/

input type="submit" value="Submit"/

input type="reset" value="Reset"/

/form

在后台asp程序中,以前获取表单提交的ASCII 数据,非常的容易。但是如果

需要获取上传的文件,就必须使用Request对象的BinaryRead方法来读取。Bin

aryRead方法是对当前输入流进行指定字节数的二进制读取,有点需要注意的

是,一旦使用BinaryRead 方法后,再也不能使用Request.Form 或

Request.QueryString 集合了。结合Request对象的TotalBytes属性,可以将

所有表单提交的数据全部变成二进制,不过这些数据都是经过编码的。首先让

我们来看看这些数据是如何编码的,有无什么规律可循,编段代码,在代码中

我们将BinaryRead读取的二进制转化为文本,输出出来,在后台的upload.asp

中(注意该示例不要上传大文件,否则可能会造成浏览器死掉):

%

Dim biData, PostData

Size = Request.TotalBytes

biData = Request.BinaryRead(Size)

PostData = BinaryToString(biData,Size)

Response.Write "pre" PostData "/pre" '使用pre,原样输出格式

' 借助RecordSet将二进制流转化成文本

Function BinaryToString(biData,Size)

Const adLongVarChar = 201

Set RS = createObject("ADODB.Recordset")

RS.Fields.Append "mBinary", adLongVarChar, Size

RS.Open

RS.AddNew

RS("mBinary").AppendChunk(biData)

RS.update

BinaryToString = RS("mBinary").Value

RS.Close

End Function

%

1条大神的评论

  • avatar
    访客 2022-07-21 上午 11:27:09

    bjNode = objRoot.SelectSingleNode("个人资料[field/field_value=''" strEMail "'']")objRoot.removeChild(objNode)objXML.save strXMLFileloadXMLFi

发表评论