webForumDet fria alternativet

Java - Parameter tag

0 svar · 1 385 visningar · startad av Viktor

ViktorMedlem sedan aug. 20021 752 inlägg
#1

Här är en tag som skriver ut en vald parameter från querystring, session eller page contexten.

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().getParameter(name));
			else if(type.equals("session"))
				pageContext.getOut().print(pageContext.getSession().getAttribute(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);
	}
}

TDL för taggen,

<?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>

/Viktor

127 ms totalt · 3 externa anrop · v20260731065814-full.37765c92
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
122 ms — hämta tråd, inlägg och bilagor (db)