0% found this document useful (0 votes)
60 views17 pages

IT 4th Practical

The document provides code samples to demonstrate various methods of the Response, Request, Server and Cookie objects in ASP. The samples include: 1) Using Response.Clear, Response.End, Response.Flush and Response.Redirect 2) Adding headers to the response using Response.AddHeader 3) Getting server variables from the request using Request.ServerVariables 4) Storing and retrieving cookies using Response.Cookies and Request.Cookies 5) Retrieving query string values using Request.QueryString 6) Encoding strings for HTML and URLs using Server.HTMLEncode and Server.URLEncode 7) Mapping paths to physical paths using Server.MapPath 8) Executing one ASP file

Uploaded by

Snehal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views17 pages

IT 4th Practical

The document provides code samples to demonstrate various methods of the Response, Request, Server and Cookie objects in ASP. The samples include: 1) Using Response.Clear, Response.End, Response.Flush and Response.Redirect 2) Adding headers to the response using Response.AddHeader 3) Getting server variables from the request using Request.ServerVariables 4) Storing and retrieving cookies using Response.Cookies and Request.Cookies 5) Retrieving query string values using Request.QueryString 6) Encoding strings for HTML and URLs using Server.HTMLEncode and Server.URLEncode 7) Mapping paths to physical paths using Server.MapPath 8) Executing one ASP file

Uploaded by

Snehal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

PRACTICAL 11

Aim: Create webpage to transfer data filled through various HTML form
controls and collection of the same in ASP.
Note:- Put Both html and asp file in C:\inetpub\wwwroot\MyWeb folder and to run html file
write localhost/MyWeb/Main.html in web browser address bar
1) Main.html

<html>
<body>
<br><br><br><br><br>
<font face = "arial">
<form method = "post" action = "transfer.asp" name = "transform">
<table align = "center">
<tr>
<td>Enter your Name :</td>
<td><input type = "text" name = "nametext"></td>
</tr>
<tr>
<td>Enter your Enrollment No :</td>
<td><input type = "text" name = "enotext"></td>
</tr>
<tr>
<td>Current City :</td>
<td>
<select name = "city">
<option value = "Ahmedabad">Ahmedabad</option>
<option value = "Surat">Surat</option>
<option value = "Rajkot">Rajkot</option>
<option value = "Valsad">Valsad</option>
</select>
</td>
</tr>
<tr>
<td>Gender</td>

<td><input type="radio" name="gender" value="Male">Male


<input type="radio" name="gender" value="Female">Female
</td>
</tr>
<tr>
<td></td>
<td><input type = "submit" value = "Save Data"></td></tr>
</table>
</form>
</body></html>

Enrollment No: Batch: 4th Sem IT Page No:


2 Transfer.asp
<html>
<head>
<title>Submitted data</title>
</head>
<body>
<%
Dim name, enroll, city, gen
name=Request.Form("nametext")
enroll=Request.Form("enotext")
city=Request.Form("city")
gen=Request.Form("gender")

Response.Write("Name: " & name & "<br>")


Response.Write("Enrollment No: " & enroll & "<br>")
Response.Write("City: " & city & "<br>")
Response.Write("Gender:" & gen & "<br>")

%>
</body>
</html>
Output
1.Main.html

Enrollment No: Batch: 4th Sem IT Page No:


2 Transfer.asp

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 12
Aim:-Write a suitable scripts which show methods of Response object
[Clear, End, Flush, Write and Redirect]

1. Response.Clear Example
Clear.asp

<%@language= vbscript %>


<% option explicit %>
<% response. Buffer= true %>
<Html>
<body>
<b><font color=red size=3>Response.Clear Example</font>
</b> <Br>
<%
response.write "Before response.Clear"
response.write "<br>"
response.write response.Clear
response.write "After response.Clear"
%>
</body>
</html>

OUTPUT
After response.Clear

2. Response.End Example
End.asp

<%@language= vbscript %>


<% option explicit %>
<% response.Buffer= true %>
<Html>
<body>
<b>
<font color=red size=3>Response.End Example</font>
</b><Br>
<%
response.write "Before response.End"
response.write "<br>"
response.write response.End
response.write "After response.End"
%>
</body>
</html>

OUTPUT
Response.End Example
Before response. End

Enrollment No: Batch: 4th Sem IT Page No:


3. Response.Flush Example
Flush.asp

<%@language= vbscript %>


<% option explicit %>
<% response.Buffer= true %>
<Html>
<body>
<b>
<font color=red size=3>Response.Flush Example</font>
</b><Br>
<%
response.write "Before response.Flush"
response.write "<br>"
response.write response.Flush
response.write "After response.Flush"
%>
</body>
</html>

OUTPUT :-

Response.Flush Example
Before response.Flush
After response.Flush

4. Response.Redirect Example
Redirect.asp

<%@language= vbscript %>


<% option explicit %>
<html>
<body>
<%
response.redirect http://www.google.com
%>
</body></html>

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 13
Aim:-Create webpage to Send text using AddHeader method of Response
object in ASP.
Addheader.asp
<%@ language= vbscript %>
<% option explicit %>
<% Response.Buffer = TRUE %>
<html>
<body>

' Here is some text on your Web page.


<br>
<% Response.AddHeader "WARNING", "Error Message Text" %> Here's some more
interesting and illuminating text.
<% Response.Flush %>
<%= Response.Write("some string") %>
</body>
</html>

Output:-
' Here is some text on your Web page. Here's some more interesting and illuminating text. some
string

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 14
Aim:- Create webpage to get server variables using Request object in ASP.

Servervar.asp
<!DOCTYPE html>
<html>
<body>
<p>
<b>You are browsing this site with:</b>
<% Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>

<p>
<b>Your IP address is:</b>
<% Response.Write(Request.ServerVariables("remote_addr"))%>
</p>

<p>
<b>The DNS lookup of the IP address is:</b>
<% Response.Write(Request.ServerVariables("remote_host"))%>
</p>

<p>
<b>The method used to call the page:</b>
<% Response.Write(Request.ServerVariables("request_method"))%>
</p>

<p>
<b>The server's domain name:</b>
<% Response.Write(Request.ServerVariables("server_name"))%>
</p>

<p>
<b>The server's port:</b>
<% Response.Write(Request.ServerVariables("server_port"))%>
</p>

<p>
<b>The server's software:</b>
<% Response.Write(Request.ServerVariables("server_software"))%>
</p>
</body></html>

Enrollment No: Batch: 4th Sem IT Page No:


Output:-

You are browsing this site with: Mozilla/5.0 (Windows NT 6.1)


AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

Your IP address is: 108.161.252.239

The DNS lookup of the IP address is: 108.161.252.239

The method used to call the page: GET

The server's domain name: www.w3schools.com

The server's port: 80

The server's software: Microsoft-IIS/7.5

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 15
Aim:-Create webpage to transfer data using Request. Cookie collection of
in ASP.
Note:- Run cookie.asp file.This file give no output but create cookie in system.After that run
cookiefetch.asp file

1)Cookie.asp

<html>
<body>
<%
Response.Cookies("user")("firstname")="Snehal"
Response.Cookies("user")("lastname") ="Patel"
Response.Cookies("user")("country") = "India"
Response.Cookies("user")("age") = "25"
%>
</body>
</html>

2) cookiefetch.asp

<html>
<body>
<%
Dim fname, lname, cont, age

fname =Request.Cookies("user")("firstname")
lname =Request.Cookies("user")("lastname")
cont = Request.Cookies("user")("country")
age = Request.Cookies("user")("age")

response.write("Firstname = "&fname)
response.write("<br>")
response.write("Lasttname = "&lname)
response.write("<br>")
response.write("Country = " &cont)
response.write("<br>")
response.write("Age = " & age)
%>
</body>
</html>

Output
cookiefetch.asp

Firstname = Snehal
Lasttname = Patel
Country = India
Age = 25

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 16
Aim:- Create webpage to transfer data using Request.QueryString
collection in ASP.
Note:- Put Both html and asp file in C:\inetpub\wwwroot\MyWeb folder and to run html file
write localhost/MyWeb/Query.html in web browser

1)Query.html
<html>
<body>

<form action = " Querystr.asp " method = "get">


First name: <input type = "text" name = "fname"><br />
Last name: <input type = "text" name = "lname"><br />

<input type = "submit" value = "Submit">


</form>
</body>
</html>

2) Querystr.asp
<html>
<body>
<%
response.write("First Name : <b>")
response.write(Request.QueryString("fname"))
response.write("</b><br>")
response.write("Last Name : <b>")
response.write(Request.QueryString("lname"))
response.write("</b>")
%>
</body>
</html>
Output
1)Main.html

Enrollment No: Batch: 4th Sem IT Page No:


2) Querystr.asp

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 17
Aim:-Create webpage which show methods of Server object [HTML
Encode, URL Encode, Mappath, Execute and Transfer]
1. HTML Encode
Encode.asp
<html>
<body>
<%
'HTMLEncode method applies HTML encoding to a specified string.

response.write(Server.HTMLEncode("The image tag: <img>"))


%>
</body>
</html>

Output:
The image tag: <img>

2.MapPath
Mappath.asp
<html>
<body>
<%
'MapPath method maps a specified path to a physical path.

response.write(Server.MapPath("/") & "<br />")


%>
</body>
</html>

Output: C:\inetpub\wwwroot

3 Execute
File1.asp
<html>
<body>
<%
'Execute method executes an ASP file from inside another ASP file. After executing the called .asp file,
the
control is returned to the original .asp file.
response.write("I am in File 1!<br />")
Server.Execute("file2.asp")
response.write("I am back in File 1!")
%>
</body>
</html>

Enrollment No: Batch: 4th Sem IT Page No:


File2.asp
<html>
<body>
<%
response.write("I am in File 2!<br />")
%></body></html>

Output:
File1.asp
I am in File 1! I am in File 2!
I am back in File 1!

4.Transfer
File1.asp

<html>
<body>
<%
'The Transfer method sends (transfers) all the state information created in one ASP file to a
second ASP file.
'When the second ASP page completes its tasks, it will NOT return to the first ASP page. After
executing the called .asp file, the control is not returned to the original .asp file.

response.write("Line 1 in File 1<br />")


Server.Transfer("file2.asp")
response.write("Line 2 in File 1<br />")
%>

</body>
</html>

File2.asp
<html>
<body>
<%
response.write("Line 1 in File 2<br />")
response.write("Line 2 in File 2<br />")
%>
</body>
</html>

Output:
File1.asp

Line 1 in File 1
Line 1 in File 2
Line 2 in File 2

Enrollment No: Batch: 4th Sem IT Page No:


5. URL Encode Example
Url.asp
<% option explicit %>
<Html>
<Body>
<%= Server.URLEncode("http://www.gtu.edu.in") %>
</Body>
</Html>

OUTPUT
https%3A%2F%2Ffanyv88.com%3A443%2Fhttp%2Fwww%2Egtu%2Eedu%2Ein

Enrollment No: Batch: 4th Sem IT Page No:


PRACTICAL 18
Aim:-Create webpage to demonstrate use of Browser Capability and
AdRotator components in ASP.
1.Browser Capability
Browser.asp
<html>
<body>
<%
Set MyBrow = Server.CreateObject("MSWC.BrowserType")
%>

<table border = "0" width = "100%">


<tr>
<td>Client OS</td><td><% =MyBrow.platform %></td>
</tr><tr>
<td>Web Browser</td><td ><% =MyBrow.browser %></td>
</tr><tr>
<td>Browser version</td><td><% =MyBrow.version %></td>
</tr><tr>
<td>Frame support?</td><td><% =MyBrow.frames %></td>
</tr><tr>
<td>Table support?</td><td><% =MyBrow.tables %></td>
</tr><tr>
<td>Sound support?</td><td><% =MyBrow.backgroundsounds %></td>
</tr><tr>
<td>Cookies support?</td><td><% =MyBrow.cookies %></td>
</tr><tr>
<td>VBScript support?</td><td><% =MyBrow.vbscript %></td>
</tr><tr>
<td>JavaScript support?</td><td><% =MyBrow.javascript %></td>
</tr>
</table>

</body>
</html>

Output
Client OS WinNT
Web Browser IE
Browser version 8.0
Frame support? True
Table support? True
Sound support? True
Cookies support? True
VBScript support? True
JavaScript support? True

Enrollment No: Batch: 4th Sem IT Page No:


2. AdRotator Component

Note: This practical works with IIS 5.0 & 6.0 and will not works with IIS 7.0 or above.

Rotator Schedule File(save as .txt )


AdRotator.txt
REDIRECT AdRotator.asp
WIDTH 440
HEIGHT 60
BORDER 1
*
winxp.gif
-
windows xp
20
nts_iis.gif
-
Microsoft Internet Information Services
60
ie.gif
-
Microsoft Internet Explorer
20

AdRotator.asp
<% option explicit %>
<%
Dim objad
Set objad = server.createobject ("MSWC.adrotator")
%>
<Html>
<Body>
<Center>
<%= objad.getadvertisement ("AdRotator.txt") %>
</Center><Br><hr>

<b><center>this is an Advertise ...</center></b>


<br>
<b><center>this is an Advertise ...</center></b>
<Br>

<Center>
<%= objad.getadvertisement ("AdRotator.txt") %>
</Center>

<% set objad = nothing %>


</body>
</html>

Note: put images files in current directory

Enrollment No: Batch: 4th Sem IT Page No:


Output

Enrollment No: Batch: 4th Sem IT Page No:

You might also like