%>"<% 이런식으로 ASP 태그를 닫아서 출력해주거나
chr(34) 함수를 이용하여 캐릭터 코드를 변환시켜서 출력해주는 수 밖에 없다.
#2008.10.28 추가
큰 따옴표를 "" 두개로 묶어주면 된다. MSSQL도 string 안에 작은 따옴표를 사용하고 싶다면 '' 두개 붙여주면 된다.
str = "<a href=""/"">home</a>"
이런식이다.
Methods for encoding and deconding text in various formats.
Used for encoding data that will be passed via a querystring variable. A querystring variable is anything following the question mark (?) in the URL (location) field of your browser. You create querystring variables when you perform a redirect or build a hyperlink to another page on your site.
<a href="page2.asp?name=Joe+Schmoe">here</a>
<%
Response.Redirect "page2.asp?ID=3"
%>In the example above, the hyperlink contains a variable named "name" which has a value of "Joe Schmoe" (the space is encoded as "+") In the Response.Redirect statement, we have a querystring variabled named "ID" with a value of 3. To perform a URL encode on a variable (for purposes of passing this variable to another page) use the following:
<a href="page2.asp?name=<%= Server.URLEncode(sName) %>">
here</a>
<%
Response.Redirect "page2.asp?ID=" &_
Server.URLEncode(nID)
%>
For some reason, Microsoft did not include a URL decode function with Active Server Pages. Most likely, this was because the decoding of querystring variables is done automatically for you when you access the querystring object:
<%= Request.QueryString("name") %>
For those of you who are desperately in need of this function:
' -----------------------------------------
' URL decode to retrieve the original value
Function URLDecode(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If
' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")
' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")
If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If
URLDecode = sOutput
End Function
This useful built-in function is very useful for encoding text that should be displayed in a form input. By "form input" we mean a web form control such as a text input, select or textarea control.
You may have noticed that certain characters cause the HTML on your web form to be interpretted incorrectly. Specifically, the HTML tag characters "<" and ">" can have this effect as well as the quote character (") which is used to encapsulate values.
<input type="text" value="<%= Server.HTMLEncode(sValue) %>">This simple value shows you how easy it is to safely include any value within a web form control.
<textarea name="sample" width=38 height=10>
<%= Server.HTMLEncode(sValue) %>
</textarea>
Just like with the URLDecode function described previously, Microsoft, in its infinite wisdom decided not to include an HTMLDecode function with their Server component. It is a relatively simple matter to decode this test data (although I haven't had a need to do this so far.) For completeness sake, here is an HTMLDecode function you may use:
Function HTMLDecode(sText)
Dim I
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, "&" , Chr(38))
sText = Replace(sText, " ", Chr(32))
For I = 1 to 255
sText = Replace(sText, "&#" & I & ";", Chr(I))
Next
HTMLDecode = sText
End Function
예전에는 php에서 이전페이지에서 넘어온, get이나 post로 넘어온 값을 가지고 처리해할 때,
바로 변수이름을 주거나 $_POST 배열을 그냥 읽었다.
예를 들어 name=janghyuk 이란 값을 post로 넘기게 되면,
$name 으로도 접근이 가능했었다. 하지만 이건 보안상 위험한 문제이고,
$_POST["name"] 으로 받는 것이 좋으나, 있는지 없는지 체크를 하지 않고 받으면
"" , empty string 으로 받아지게 된다.
아예 post로 해당 값이 들어왔는지 체크를 하기 위해서,
if( array_key_exists( 'name', $_POST ) ) 로 체크하면 확실히 넘어왔는지 여부를 가릴 수 있다.
On Error Resume Next '// ERROR CHECKING
If err <> 0 Then '// ERROR OCCURRED
'// 에러처리
End If
On Error Goto 0 '// Clear Errors
On Error Resume Next '// NEW ERROR CHECKING
