好贷网好贷款

JSP Tag实现定义 java文件

发布时间:2016-12-3 8:23:24 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"JSP Tag实现定义 java文件",主要涉及到JSP Tag实现定义 java文件方面的内容,对于JSP Tag实现定义 java文件感兴趣的同学可以参考一下。

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples; import java.io.IOException; import java.io.InputStream; import java.util.Locale; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; /** * Display the sources of the JSP file. */ public class ShowSource extends TagSupport { private static final long serialVersionUID = 1L; String jspFile; public void setJspFile(String jspFile) { this.jspFile = jspFile; } @Override public int doEndTag() throws JspException { if ((jspFile.indexOf( ".." ) >= 0) || (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/WEB-INF/") != 0) || (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/META-INF/") != 0)) throw new JspTagException("Invalid JSP file " + jspFile); InputStream in = pageContext.getServletContext().getResourceAsStream(jspFile); if (in == null) throw new JspTagException("Unable to find JSP file: "+jspFile); JspWriter out = pageContext.getOut(); try { out.println("<body>"); out.println("<pre>"); for(int ch = in.read(); ch != -1; ch = in.read()) if (ch == '<') out.print("<"); else out.print((char) ch); out.println("</pre>"); out.println("</body>"); } catch (IOException ex) { throw new JspTagException("IOException: "+ex.toString()); } return super.doEndTag(); } }

上一篇:GridView在使用CommandField删除时提示确认框
下一篇:POJ 2104 & HDU 2665 K-th Number (划分树)

相关文章

相关评论