Jsp tag file例子以及说明(5)
else
encodedTag.append(c);
}
return encodedTag.toString();
}
%>
<%=encodeHtmlTag(input)%>//根据传入的参数input调用方法encodeHtmlTag
编译后的代码
encode_tag.java
[java]
public final class encode_tag
extends javax.servlet.jsp.tagext.SimpleTagSupport
implements org.apache.jasper.runtime.JspSourceDependent {
private String encodeHtmlTag(String tag) {
if (tag==null)
return null;
int length = tag.length();
StringBuffer encodedTag = new StringBuffer(2 * length);
for (int i=0; i<length; i++) {
char c = tag.charAt(i);
if (c=='<')
encodedTag.append("<");
else if (c=='>')
encodedTag.append(">");
else if (c=='&')
encodedTag.append("&");
else if (c=='"')
encodedTag.append(""");
else if (c==' ')
encodedTag.append(" ");
else
encodedTag.append(c);
}
return encodedTag.toString();
}
....
private java.lang.String input;
public java.lang.String getInput() {
return this.input;
}
public void setInput(java.lang.String input) {
this.input = input;
jspContext.setAttribute("input", input);
}
......
public void doTag() throws javax.servlet.jsp.JspException, java.io.IOException {
javax.servlet.jsp.PageContext _jspx_page_context = (javax.servlet.jsp.PageContext)jspContext;
javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest) _jspx_page_context.getRequest();
相关新闻>>
- 发表评论
-
- 最新评论 更多>>