PSP

[ Start > PikeApps > PSP ] [ Edit this Page | Show Page Versions | Show Raw Source ]


As of version 0.2, Pike ScriptRunner can be used to run Pike Server Pages (PSP) files. A Standalone PSP parser is also available. PSP is similar to JSP in that it allows you to mix code and content on the same page. The PSP markup format is:

Expressions

<%= someexpression %>   gives you some expression cast as a string.

for example:

<%= random(100) %> is a positive random number less than 100.

The RequestID object is available as "request" in expressions, as is "out". See the scriptlets section for more information.

Scriptlets

PSP allows code to be inserted into the page as part of the request handling method. This code is called a "Scriptlet".

<%  somepikecode %>   inserts some pike code fragments in page (aka scriptlet)

for example

<% 
    for(int a = 99; a > 0; a--)
    {
      out+= (a + " bottles of beer on the wall.&#110;<p>");
    }
%>

The RequestID object is available as "request".

The object "out" is available and is a String.Buffer. All of your output should be + or add()ed to this object.

return doesn't play a role here; don't use it!

blocks of non-psp markup are considered a block, so you can do this:

<% if(id->variables->somevar) %>
all this
appears if somevar is present and non-zero.
<% else %>
all of this appears otherwise, until we hit another <% %> (ie this shows up
regardless) block.

note that you can use {} in these cases to force the situation, as all text blocks get converted automatically to output().

Declarations

PSP allows you to define methods and include page global objects and variables that remain after the request has finished. These items may be defined using the declaration syntax:

<%!
     some pike code
%>

this code will be placed inside the servicing object, but outside of the page servicing method, so you can use this "directive" tag to define additional methods, perform inherits and includes, and so forth.

Directives

Directives allow you to perform certain operations that may be important to the functioning of your page. Currently, the content-type and include directives are implimented.

<%@ include file="" %>
<%@ content-type type="mime/type" %>
<%@ use-session %>

the first directive, include, will include some other file into the current file, and will be parsed as a psp fragment. currently, absolute paths are properly supported, relative to the document root. relative paths have undefined behavior at this point. more work needs to be done on this.

the second directive, content-type, will set the return MIME type for the content returned.

the third directive, use-session, will cause session information to be stored and retrieved for this page.


Powered by PikeWiki2

 
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University