1 13 package com.tonbeller.wcf.utils; 14 15 import java.io.IOException ; 16 17 import javax.servlet.RequestDispatcher ; 18 import javax.servlet.ServletException ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.tagext.TagSupport ; 22 23 import org.apache.log4j.Logger; 24 25 33 34 public class IncludeTag extends TagSupport { 35 String httpParam = "include"; 36 String prefix = "/WEB-INF/"; 37 String suffix = ".jsp"; 38 private static Logger logger = Logger.getLogger(IncludeTag.class); 39 40 public String getHttpParam() { 41 return httpParam; 42 } 43 44 public void setHttpParam(String httpParam) { 45 this.httpParam = httpParam; 46 } 47 48 public int doStartTag() throws JspException { 49 try { 50 logger.info("enter"); 51 HttpServletRequest hsr = (HttpServletRequest ) pageContext.getRequest(); 52 53 String name = hsr.getParameter(httpParam); 54 if (name != null) { 55 String uri = prefix + name + suffix; 57 logger.info("including " + uri); 58 RequestDispatcher rd = pageContext.getRequest().getRequestDispatcher(uri); 59 rd.include(pageContext.getRequest(), pageContext.getResponse()); 60 } 61 logger.info("leave"); 62 return SKIP_BODY; 63 } catch (ServletException e) { 64 logger.error("exception caught", e); 65 throw new JspException (e); 66 } catch (IOException e) { 67 logger.error("exception caught", e); 68 throw new JspException (e); 69 } 70 } 71 72 public String getPrefix() { 73 return prefix; 74 } 75 76 public String getSuffix() { 77 return suffix; 78 } 79 80 public void setPrefix(String prefix) { 81 this.prefix = prefix; 82 } 83 84 public void setSuffix(String suffix) { 85 this.suffix = suffix; 86 } 87 88 } 89 | Popular Tags |