PSP Environment

All of the code you write within the PSP is effectivly wrapped inside of the execute method of a Page object. As such, you have available to you all of the facilities and methods of a Page object. This includes access to the Request object, the Response object, if your PSP is a session page, you also have access to a session object, and, of course, you have a $self which is the Page object itself.

The Query Object

You can use the $self->query to access the query object, which is a CGI object. You can use the query object to access query string data, POST parameters.

<HTML>
<BODY BGCOLOR="#FFFFFF">
<P> Query Data: </P>
<TABLE BORDER=1 ALIGN=CENTER>
<% foreach my $key ( $self->query->param ) { %>
  <TR>
    <TD><%= $key %></TD><TD><%= $self->query->param( $key ) %></TD>
  </TR>
<% } %>
</TABLE>
</BODY>
</HTML>
    

The query object can also be used to generate HTML. Using the query to produce form elements is a very useful techniuqe, because the CGI object will automatically fill in values for the form elements if they were present in the query.

<HTML>
<BODY BGCOLOR="#FFFFFF">
<P> Questionaire: </P>
<FORM ACTION="/pas/questionaire/Questionaire" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="answering_questionaire">
<TABLE BORDER=1 ALIGN=CENTER>
  <TR>
    <TD> First Name: </TD>
    <TD> <%= $self->query->textfield('first_name') %> </TD>
  </TR>
  <TR>
    <TD> Last Name: </TD>
    <TD> <%= $self->query->textfield('last_name') %> </TD>
  </TR>
  <TR>
    <TD> Marital Status: </TD>
    <TD> <%= $self->query->popup_menu( 'marital_status', ['Married','Single','Other' ) > </TD>
  </TR>
</TABLE>
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit">
</FORM>
</BODY>
</HTML>
    

The Response Object

The response object would mainly be used to perform operations such as setting a new cookie, an HTTP expires header to be returned for the page, or set an HTTP redirect.

<HTML>
<BODY BGCOLOR="#FFFFFF">
<P> You took a chance... </P>
<%
  if( rand(1) < 0.5 ) {
    return $self->response->set_redirect('http://www.yahoo.com/');
  }
%>

<P> and you got in!  </P>
</BODY>
</HTML>