Här är en tag som skriver ut en vald parameter från querystring, session eller page contexten.
[kod]
package com.vgsoftware.vglib.util;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class ParamTag extends TagSupport
{
public String name=null;
public String type=null;
public int doEndTag()
throws JspTagException
{
try
{
if(type==null||type.equals("query"))
pageContext.getOut().print(pageContext.getRequest().getParam eter(name));
else if(type.equals("session"))
pageContext.getOut().print(pageContext.getSession().getAttri bute(name));
else if(type.equals("page"))
pageContext.getOut().print(pageContext.getAttribute(name));
}
catch(java.io.IOException io)
{
throw(new JspTagException(io.getMessage()));
}
return(EVAL_PAGE);
}
public void setType(String type)
{
this.type=type;
}
public String getType()
{
return(type);
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return(name);
}
}
[/kod]
TDL för taggen,
[kod]
<?xml version="1.0"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>vglib</shortname>
<info>
</info>
<tag>
<name>param</name>
<tagclass>com.vgsoftware.vglib.util.ParamTag</tagclass>
<info></info>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<!--
Here you can set the type of variable that will be read.
Default is from the querystring, but ok values here are
query (querystring)
session (session object)
page (page context)
-->
<name>type</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
[/kod]
/Viktor
[kod]
package com.vgsoftware.vglib.util;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class ParamTag extends TagSupport
{
public String name=null;
public String type=null;
public int doEndTag()
throws JspTagException
{
try
{
if(type==null||type.equals("query"))
pageContext.getOut().print(pageContext.getRequest().getParam eter(name));
else if(type.equals("session"))
pageContext.getOut().print(pageContext.getSession().getAttri bute(name));
else if(type.equals("page"))
pageContext.getOut().print(pageContext.getAttribute(name));
}
catch(java.io.IOException io)
{
throw(new JspTagException(io.getMessage()));
}
return(EVAL_PAGE);
}
public void setType(String type)
{
this.type=type;
}
public String getType()
{
return(type);
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return(name);
}
}
[/kod]
TDL för taggen,
[kod]
<?xml version="1.0"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>vglib</shortname>
<info>
</info>
<tag>
<name>param</name>
<tagclass>com.vgsoftware.vglib.util.ParamTag</tagclass>
<info></info>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<!--
Here you can set the type of variable that will be read.
Default is from the querystring, but ok values here are
query (querystring)
session (session object)
page (page context)
-->
<name>type</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
[/kod]
/Viktor