package com.acme.tag; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import javax.naming.*; /** * A Tag for reading environment entries * @author Magnus Rydin */ public class GetEnvEntryTag extends TagSupport { private String name; private String type; public GetEnvEntryTag() { super(); } /** * Method used by the JSP container to set the parameter Name. */ public void setName(String name) { this.name=name; } /** * Method used by the JSP container to set the parameter Type. */ public void setType(String type) { this.type=type; } /** * Method Called at end of Tag * @return either EVAL_PAGE or SKIP_PAGE */ public int doEndTag() throws javax.servlet.jsp.JspTagException { try{ InitialContext context=new InitialContext(); //get the env-entry Object obj=(Object)context.lookup("java:comp/env/"+name); //add the env-entry to the page scope pageContext.setAttribute(name,obj,PageContext.PAGE_SCOPE); }catch(javax.naming.NamingException ne){ throw new JspTagException(ne.getMessage()); } return EVAL_PAGE; } }