Home > Articles > Mobile Application Development & Programming > HTML5 & Web Standards

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Added Value

Here's the code for addTo.asp:

1  <%
2  Dim query, refer
3  refer = Request.ServerVariables("HTTP_REFERER")
4  check_op()

Starting simply, we define a couple of variables and call the function check_op().

5  '#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#
6  function check_op
7  'Checks query string to see which command to run
9   dim resp
11  if Request.QueryString("command") = "add" then
12   if Request.QueryString("readd") = "yes" then
13    resp = readdContent()
14    if resp = -1 then
15    resp = "<p>The content could not be added</p>"
16    resp = resp & "<p align=center>
           <input type='button' name='close'
           value='Close' onClick='window.close()'></p>"
17    end if
18   else
19   resp = addContent()
20   if resp = -1 then
21    resp = "<p>The content could not be added</p>"
22    resp = resp & "<p align=center>
         <input type='button' name='close' value='Close'
23   elseif resp = -2 then
24    resp = "<p align=""center"">
         The content could not be added</p>
          <p align=""center"">Please Log In to
          MyInformIT before saving any content</p>"
25    resp = resp & "<p align=center>
         <input type='button' name='close' value='Close'
26   end if
27  end if

Let's break at this point. The function check_op() also checks for a command = delete argument and does some error handling, but we'll get to that functionality later on. Our query string did indeed have the command = add argument, so the initial if statement on line 11 is true.

The first thing it does is check whether another argument, readd = yes, exists. This argument gets applied by the JavaScript I singled out above. I'm not quite ready to discuss that yet, so we'll assume that readd is not in the query string. The next thing that happens is a call to addContent(). addContent() returns a numerical response value. From the error messages that are assigned to resp (a useful little variable), you can guess at what occurred in addContent(). Below, we'll find out for sure.

1  '#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#
2  function addContent
3  'Adds the current page (if it has an associated productID)
4  ' to the user's MyInformIT entries
5  'Gets information from query string
7   dim elobj,addobj
8   dim prodID
9   dim elID
10   dim sessID,userRS,userID
11   dim prodInfo,prodset(3)
12   dim elDesc
13   dim elname
14   dim ret,resp
16   if Request.QueryString("product_id") = "" then
17   'No product ID? Something is screwy, send them back
18   ' the way they came
19    addContent = -1

Right off the bat, addContent() checks for the product_id. No product_id, no dice. On the other hand, if the product_id exists...

20   else
21   'A product ID has been passed to the page
22    prodID = Request.QueryString("product_id")
23    set elobj = Server.CreateObject("informit.Content")
24    elobj.getProductInfo(prodID)
25    set prodInfo=elobj.items

...we use it to grab all sorts of useful information about the product from the database.

We create an object from the Java class, informit.Content, and call the method getProductInfo, passing in our product_id. The curious next step is of some interest. On line 25 we set the variable prodInfo to the public method elobj.items. Rather than defining the getProductInfo method as type Recordset, and passing back the data directly, getProductInfo is defined as type void. A public variable named ritems is defined as type Recordset in the Content class. ritems is equated to the results returned from the stored procedure call invoked in getProductInfo. Then, for the ASP to access the Recordset, the public method items is called to fetch the data. The relevant lines look like this in Java code snippets:

public Recordset ritems;

public void getProductInfo(String productID)

public IDataSource items()
  return (IDataSource)ritems.getDataSource();

This seemingly roundabout way of accessing the recordset data is actually much more favorable in terms of memory usage. Instead of returning a Recordset to the ASP, getDataSource() returns a pointer to the data. On a site performing as many database calls as InformIT, with as many users, every bit of memory performance is precious.

  • + Share This
  • 🔖 Save To Your Account