ASP 예제 코드 17개

1. Displaying the current date and time:
<%
dim currentDate
currentDate = date()
response.write("Today's date is " & currentDate)
%>
=====================================
2. Redirecting to another page:
<%
response.redirect("https://www.example.com")
%>
=====================================
3. Creating a form with text inputs:
<form action="submit.asp" method="post">
<input type="text" name="name" placeholder="Enter your name">
<input type="text" name="email" placeholder="Enter your email">
<input type="submit" value="Submit">
</form>
=====================================
4. Retrieving data from a database:
<%
dim conn, rs, sql
set conn = server.createObject("ADODB.Connection")
conn.open "Driver={SQL Server};Server=localhost;Database=myDB;Uid=myUsername;Pwd=myPassword;"
sql = "SELECT * FROM Customers"
set rs = conn.execute(sql)
while not rs.EOF
response.write("Name: " & rs("Name") & "<br>")
response.write("Email: " & rs("Email") & "<br>")
rs.MoveNext
wend
rs.Close
set rs = nothing
conn.Close
set conn = nothing
%>
=====================================
5. Creating a session variable:
<%
session("user") = "John Doe"
response.write("Welcome, " & session("user"))
%>
=====================================
6. Writing a cookie:
<%
dim cookie
set cookie = response.cookies("visitcount")
cookie.expires = date() + 30
if cookie("count") = "" then
cookie("count") = 1
else
cookie("count") = cookie("count") + 1
end if
response.write("This is your " & cookie("count") & " visit to this site.")
%>
=====================================
7. Creating an if-else statement:
<%
dim score
score = 85
if score >= 60 then
response.write("Passed")
else
response.write("Failed")
end if
%>
=====================================
8. Creating a for loop:
<%
for i = 1 to 10
response.write(i & "<br>")
next
%>
=====================================
9. Creating a function:
<%
function addNumbers(a, b)
addNumbers = a + b
end function
response.write("The sum of 5 and 3 is " & addNumbers(5, 3))
%>
=====================================
10. Displaying a random image:
<%
dim images(3), randomNum
images(0) = "image1.jpg"
images(1) = "image2.jpg"
images(2) = "image3.jpg"
randomNum = Int(Rnd * 3)
=====================================
11. Creating an array:
<%
dim colors(3)
colors(0) = "red"
colors(1) = "green"
colors(2) = "blue"
response.write("The first color in the array is " & colors(0))
%>
=====================================
12. Creating a switch case statement:
<%
dim day
day = "Monday"
select case day
case "Monday"
response.write("Today is Monday.")
case "Tuesday"
response.write("Today is Tuesday.")
case "Wednesday"
response.write("Today is Wednesday.")
case else
response.write("Today is not Monday, Tuesday, or Wednesday.")
end select
%>
=====================================
13. Retrieving data from a query string:
<%
dim name
name = Request.QueryString("name")
response.write("Hello, " & name)
%>
=====================================
14. Creating a dynamic dropdown list:
<%
dim i, colors(3)
colors(0) = "red"
colors(1) = "green"
colors(2) = "blue"
%>
<select>
<% for i = 0 to UBound(colors) %>
<option value="<%=colors(i)%>"><%=colors(i)%></option>
<% next %>
</select>
=====================================
15. Uploading a file:
<form action="upload.asp" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
<%
dim file
set file = Request.Files("file")
file.SaveAs Server.MapPath(".") & "\uploads\" & file.FileName
%>
=====================================
16. Creating a while loop:
<%
dim i
i = 1
while i <= 10
response.write(i & "<br>")
i = i + 1
wend
%>
=====================================
17. Sending an email:
<%
dim mail
set mail = server.createObject("CDO.Message")
mail.From = "sender@example.com"
mail.To = "recipient@example.com"
mail.Subject = "Test Email"
mail.TextBody = "This is a test email sent from ASP."
mail.Send
%>
홈페이지 / PHP / ASP /JAVA / JSP 유지보수
셈틀컴퍼니 1688-8802
PHP 유지보수, 홈페이지 유지보수, 웹사이트 유지보수, 셈틀컴퍼니
PHP,MySQL,홈페이지 유지보수, 웹사이트 유지보수,LINUX서버유지보수, 리눅스,윈도우서버 관리, JAVA, ASP, PHP 유지보수
samtle.com
캠핑/글램핑장 창업 및 실시간 예약솔루션 (에어바운스캠프)
셈틀컴퍼니 1688-8802
에어바운스캠프
에어바운스,캠핑장 운영,실시간 예약시스템
naeils.co.kr