Differences between JSP and ASP

Java is the typical programming language for Java Server Pages (JSPs). For Active Server Pages (ASP), the typical language is VBScript. This document reviews the differences between the two languages and technologies for common constructs.

Here are some useful references on ASP:

Common tags

JSP and ASP often use the same tags:

Code <% code in java or VBScript %>
Expression <%= expression %>

However, VBScript uses a single quote to start a comment while Java uses two slashes to start a comment on the same line.

Common expressions

Description JSP ASP
Writing HTML code out.print("Some HTML code"); Response.Write "Some HTML code"
Obtaining a parameter value request.getParameter("parameterName") Request("parameterName")
Null value null Nothing

Also, Request.QueryString("currency").count returns how many parameter values the "currency" attribute has. This is useful for determining if the "currency" attribute has a value by testing whether the count has zero. The QueryString method only works for the GET method. For POST, use the Form method.

Variable declarations

Java is a strongly-typed language and its variables must have their types declared before they are used. For VBScript, declaring variables is strongly advised but not necessary. The types are not specified for the declaration.

Java examples

    int num;
    double amount;
    int list[] = new int[10];  // holds 10 integers

VBScript examples

    Dim num, amount;
    Dim list(10)  'stores 10 items of any type

Note: If the ASP page has the statement Option Explicit near the top of the page, all variables must be declared.


Java examples

    num = 10;

    if (num == 10) {
        out.print("Num: " + num);
    else {
        out.print("Answer is not 10");

    // list is an array of strings
    for (int i = 0; i < list.length; i++) {

VBScript examples

    Set num = 10

    If num = 10 Then
        Response.Write "Num: " & num
        Response.Write "Answer is not 10"
    End If

    'list is an array of strings
    For Each name in list
       Response.write name

Normally VBScript statements end at the end of the line (semicolons are not used). If the programmer wants a statement to continue on the next line, a "_" is added at the end of the line to show that the statement continues on the next line.

Statement keywords are capitalized in VBScript.

See DevGuru for list of VBScript statements.

Calling methods

Java examples



VBScript examples

    Response.Write "output"


Note that ASP method calls when used as statements do not use parentheses for their arguments (unless the keyword "Call" precedes the object and method names). Parentheses are used when the method call is used as an expression.

Error handling

Java throws exceptions when it tries to process invalid methods or data. In contrast, for VBScript, the programmer must explicitly check for invalid data or an invalid result. For example, to check whether a parameter is a valid number, the programmer could create the following if statement:

    Dim response
    response = Request("amount")
    If Not IsNumeric(response) Then
       Response.Write "This amount is not valid!"
    End If

Database access

ASP pages usually use the ADO libraries to access a database. See ShowCurrencies.asp for an example of connecting to a database, issuing a query and displaying the reuslts. DevGuru provides a good reference to the ADO objects and methods.

Last modified: Thu Oct 16 14:12:51 Central Daylight Time 2003