⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ejbhometag.java

📁 < J2EE应用开发详解>>一书全部的源代码. 本书基于J2EE 1.4平台
💻 JAVA
字号:
package com.j2ee14.ch11;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import javax.ejb.*;
import javax.naming.*;
import com.j2ee14.ch1.*;

public class EJBHomeTag extends TagSupport
{
    protected String name;
    protected String type;
    String context=null;

    /** Sets the JNDI name to use when looking for the EJBHome
     * @param name a JNDI name
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /** Sets the EJBHome classtype
     * @param type the classtype
     */
    public void setType(String type)
    {
        this.type = type;
    }
    public void setContext(String p)
    {
    	this.context=p;
    }
    

    /** Start of Tag
     * @throws JspException
     * @return
     */
    public int doStartTag() throws JspException
    {
        try {
            InitialContext init;
            if(context!=null)
            {
            	Properties p=new Properties();
            	p.load(EJBHomeTag.class.getResourceAsStream(context));
            	p.list(System.out);
            	System.out.println(name);
            	init = new InitialContext(p);
            }
            else
             	init = new InitialContext();
            ClassLoader classLoader=
                pageContext.getPage().getClass().getClassLoader();
           EJBHome home =
					(EJBHome)javax.rmi.PortableRemoteObject.narrow(
					init.lookup("java:comp/env/"+name),
					Class.forName(type, true, classLoader));
            pageContext.setAttribute(this.getId(), home);

            return SKIP_BODY;
        }
        
        catch(NamingException e) {
        	            e.printStackTrace();
            throw new JspTagException("NamingException: " + e.getMessage());

        } catch(Exception e) {
            throw new JspTagException("ClassNotFoundException: " + e.getMessage());
        }
    }

    public int doEndTag() 
        throws JspException 
    {
        name = null;
        type = null;
        return super.doEndTag();
    }
    
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -