Servlet containers are typically configured so that pnuts::servlet module can be used by servlet scripts. The following functions in the pnuts::servlet module make servlet scripting easier.
|
readPostParameters() reads the POST data sent by web client. readGetParameters() reads GET parameters. readParameters() reads both POST data and GET parameters.
The return value is a script package from which the parameters can be read. encoding is one of Java's encoding name If encoding is not specified, "UTF8" is used as the character encoding.
These functions are provided because ServletRequest.getParamter() does not support encodings other than ISO8859_1. readPostParameters() and readParameters() can not be mixed with ServletRequest.getParameter() method.
e.g.
response.setContentType("text/html; charset=UTF8") if (request.getMethod() == "POST"){ postParam = readPostParameters(request, "UTF8") param1 = postParam.get("param1") ... }
|
addCookie() adds a Cookie. name and value are encoded in UTF8 and then translated into x-www-form-urlencoded format.
|
getCookie() gets a Cookie value. It assumes that the cookie name and the value are encoded in UTF8 and transformed into x-www-form-urlencoded format.
|
getFile() gets the java.io.File object which represents the servlet script file.
To execute a part of servlet script exclusively, use sync() function with the value of getFile() function. For example, a simple access counter can be written as follows.
e.g.Alternatively,
function _addCount(){ count = readCount() writeCount(++count) } addCount = sync(_addCount, getFile()) addCount()
addCount = sync(function (){ count = readCount() writeCount(++count) }, getFile()) addCount()