Class GetParamsTag

All Implemented Interfaces:
javax.servlet.jsp.tagext.IterationTag,, javax.servlet.jsp.tagext.Tag

public class GetParamsTag
extends javax.servlet.jsp.tagext.TagSupport

This class is a custom tag that renders the JWPGetParams() Javascript function which can be called to retrieve the value of a named parameter, or an array of all parameters, that were on the query string used to access the page. If there were no parameters, null will be returned in either case. Not that this function DOES NOT work on pages you manually open from a browser (i.e., if you open a local HTML file with a query string appended).

This tag uses the following attributes:

renderScriptTags - true/false - When set to true, the Javascript will be rendered inside a <script> </script> tag pair. When set to false, this will not be done and it is expected that the <jstags:fullTrim/> tag appears inside a <script> </script> tag pair. If this attribute is not present, the script tags WILL be rendered.

It renders the following Javascript:

function JWPGetParams(jwpgp_inParamName) {
retVal = null;
varvals = unescape(;
if (varvals) {
search_array = varvals.split("&");
temp_array = new Array();
j = 0;
for (i = 0; i < search_array.length; i++) {
temp_array = search_array[i].split("=");
pName = temp_array[0];
pVal = temp_array[1];
if (jwpgp_inParamName == null) {
if (retVal == null) {
retVal = new Array();
retVal[j] = pName;
retVal[j + 1] = pVal;
j = j + 2;
} else {
if (pName == jwpgp_inParamName) {
retVal = pVal;
return retVal;

Usage example:

myParam = JWPGetParams("param1");
This will return the value of the parameter named "param1", if present, or null if not present.

myParams = JWPGetParams();
This will return an array in the variable myParams which contains all the parameters and values passed to this page. Elements of the array are a repeating contiguous pattersn of name, value.

Frank W. Zammetti.
See Also:
Serialized Form

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String renderScriptTags
          Whether to render the opening and closing script tags around the emitted Javascript.
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
Fields inherited from interface javax.servlet.jsp.tagext.Tag
Constructor Summary
Method Summary
 int doStartTag()
          Render the results of the tag.
 void setRenderScriptTags(java.lang.String inRenderScriptTags)
          renderScriptTags mutator.
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


private static org.apache.commons.logging.Log log
Log instance.


private java.lang.String renderScriptTags
Whether to render the opening and closing script tags around the emitted Javascript.

Constructor Detail


public GetParamsTag()
Method Detail


public void setRenderScriptTags(java.lang.String inRenderScriptTags)
renderScriptTags mutator.

inRenderScriptTags - renderScriptTags.


public int doStartTag()
               throws javax.servlet.jsp.JspException
Render the results of the tag.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Return code.
javax.servlet.jsp.JspException - If anything goes wrong

Copyright 2005 Frank W. Zammetti