๐Ÿงฐ Common ASP References (Shared)
Estimated reading: 4 minutes 281 views

ASP โ€“ Response / Request โ€“ Handle Server Communication in Classic ASP

Introduction โ€“ What Are Response and Request in Classic ASP?

In Classic ASP, the Request and Response objects are core components that allow your server-side scripts to interact with browser clients.

  • Request is used to receive data from a client (such as form input, cookies, or query strings).
  • Response is used to send data back to the client (such as HTML content, headers, cookies, or redirects).

In this guide, youโ€™ll learn:

  • How to use the Request object to retrieve user input
  • How to use the Response object to send content and headers
  • Real-world usage with forms, cookies, and redirects
  • Output examples and best practices

The Request Object โ€“ Receiving Client Data

Common Request Collections

CollectionDescription
Request.FormData from HTML forms using POST
Request.QueryStringData from the URL (GET method)
Request.CookiesCookies sent by the client
Request.ServerVariablesInfo about the server and environment
Request.HeadersHTTP headers sent from client (IIS 5+)

Example: Read Form Input

HTML form (POST):

<form method="post" action="submit.asp">
  <input type="text" name="username">
  <input type="submit" value="Submit">
</form>

submit.asp (ASP):

<%
Dim user
user = Request.Form("username")
Response.Write "Hello, " & user
%>

Output:
Hello, Alex (if Alex was entered)


Example: Read Query String Parameters

<%
Dim page
page = Request.QueryString("id")
Response.Write "Page ID: " & page
%>

URL: example.asp?id=5
Output: Page ID: 5


Example: Access Client Cookies

<%
Dim theme
theme = Request.Cookies("Theme")
Response.Write "Your theme: " & theme
%>

The Response Object โ€“ Sending Output to Browser

Basic Output with Response.Write

<%
Response.Write "Welcome to my site!"
%>

Output:
Welcome to my site!


Redirect to Another Page

<%
Response.Redirect "home.asp"
%>

Immediately redirects the user to home.asp.


Set a Cookie

<%
Response.Cookies("Theme") = "Dark"
Response.Cookies("Theme").Expires = Date + 30
%>

Sets a cookie named Theme valid for 30 days.


Set Content Type (e.g., JSON or CSV)

<%
Response.ContentType = "application/json"
Response.Write "{""status"":""success""}"
%>

Used in API or AJAX responses.


Common Mistakes to Avoid

MistakeCorrection
Using Request("field") without checkingUse IsEmpty() or Len() to validate input
Writing to Response after RedirectAlways Exit after Response.Redirect()
Not escaping user inputAlways sanitize inputs to prevent XSS or SQLi

๐Ÿง˜ Bonus: Loop Through All Form Values

<%
Dim field
For Each field In Request.Form
    Response.Write field & ": " & Request.Form(field) & "<br>"
Next
%>

Output: Displays all submitted form fields and their values.


Best Practices for Request/Response

Do:

  • Use Request.Form("field") for POST data
  • Always validate and sanitize input values
  • Use Response.Write to debug server logic
  • Exit immediately after Response.Redirect

Avoid:

  • Mixing GET and POST unless intentional
  • Trusting Request data directly in queries
  • Forgetting to set ContentType for APIs

Summary โ€“ Recap & Next Steps

The Request and Response objects are the heartbeat of Classic ASP communication. Together, they allow your ASP pages to receive user input, send dynamic content, and manage browser interaction smoothly.

Key Takeaways:

  • Use Request.Form and Request.QueryString to capture input
  • Use Response.Write, Redirect, and Cookies to control output
  • Always validate and sanitize data from Request

Real-world Use Cases:

  • Handling form submissions
  • Redirecting users after login
  • Setting language/theme preferences using cookies

FAQs โ€“ Classic ASP Request / Response


What’s the difference between Request.Form and Request.QueryString?
Request.Form is for POST data, while Request.QueryString reads from the URL (GET data).


How do I output a variable in Classic ASP?
Use Response.Write, or the shorthand <%= variable %>.


Can I write to the response after a redirect?
No. Use Response.Redirect("url") followed by Response.End or Exit.

Share Now :
Share

๐Ÿ“ค ASP โ€“ Response / Request

Or Copy Link

CONTENTS
Scroll to Top