Lotus关于获取URL字符串参数
Published by admin on 07月 31, 2010
在B/S结构开发中,我们需要经常使用从URL链接中包含特定的参数或数据信息以用于获取相应的数据用于展现相应的动态页面。在早先的JSP\ASP,这样的方法使用很简单的Request内置对象来代替。但是在Lotus中却没有这样的机制,你需要自己编写方法来解析这些字符串。
下面是在项目开发过程中,根据之前同事编写的函数进行参数的简化更加符合正常的使用习惯。
【说明】需要在表单上设置一个显示时计算的域,在其中输入公式:@UrlQueryString
如果需要解码可以使用
@UrlDecode(“Domino”;@UrlQueryString)或@UrlDecode(“Platform”;@UrlQueryString)
函数:getParamByName
参数:所需要获取URL字符串标记名称
过程:从形如…?…&….&…的串中提取数据,假设?OpenAgent&key1=value1&key2=value2,使用getParamByName(key1)将返回value1,使用getParamByName(key2)返回value2,其他数据将返回空串。
Function getParamByName (Byval key As String)As String
Dim curDoc As NotesDocument
Dim session As New NotesSession
Dim QueryString,keyValue As String
Dim pos,nextPos, equalPos,lenKey As Integer
Set curDoc=session.DocumentContext
QueryString=curDoc.Query_String(0)
pos=Instr(1,QueryString,“&”+key)
If pos>=1 Then
lenKey=Len(key)
nextPos=Instr(pos+lenKey+1,QueryString,“&”)
If nextPos>=pos+lenKey+1 Then
‘&Key1=12&key2=value2
‘1 5 9
keyValue=Right(Left(QueryString,nextPos-1),nextPos-pos-lenKey-2)
Else
‘&Key1=12
‘1 5678
keyValue=Right(QueryString,Len(QueryString)-pos-lenKey-1)
End If
equalPos=Instr(1,keyValue,“=”)
If equalPos>=1 Then
keyValue=Right(keyValue,Len(keyValue)-equalPos)
End If
getParamByName =keyValue
Else
getParamByName =“”
End If
End Function
Pages: 1 2

Add A Comment