一、使用TagSupport类案例解析

1.自定义Tag使用jdbc连接mysql数据库

1.1定义标签处理器类

package com.able.tag;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport; public class DBconnectionTag extends TagSupport {
private String driver;// 连接驱动
private String url;// 连接db地址
private String password;// 连接db密码
private String sql;// 查询sql
private String username;// 连接db用户名
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
@Override
public int doEndTag() throws JspException {
try {
Class.forName(this.driver);
conn = DriverManager.getConnection(this.url,this.username,this.password);
stmt = conn.createStatement();
rs = stmt.executeQuery(this.sql);
if (rs != null) {
while (rs.next()) {
pageContext.getOut().print(rs.getString("cname")+"<br/>");
}
}
return EVAL_PAGE;
} catch (Exception e) {
e.printStackTrace();
return SKIP_PAGE;
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
} public String getDriver() {
return driver;
} public void setDriver(String driver) {
this.driver = driver;
} public String getUrl() {
return url;
} public void setUrl(String url) {
this.url = url;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getSql() {
return sql;
} public void setSql(String sql) {
this.sql = sql;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
}
}

1.2 在tag.tld文件中添加tag标签

 <tag>
<name>DBconnectionTag</name><!-- 定义标签名 -->
<tag-class>com.able.tag.DBconnectionTag</tag-class>
<body-content>empty</body-content> <!-- 定义标签体为空 -->
<attribute>
<name>driver</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue><!-- 可以使用el表达式接收参数 -->
</attribute>
<attribute>
<name>url</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>username</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>password</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>sql</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

1.3 定义jsp,页面引入标签库,并定义标签

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<tm:DBconnectionTag url="jdbc:mysql://192.168.9.223:3306/test_2016" driver="com.mysql.jdbc.Driver" username="root" password="ablejava" sql="select * from course"/>
<br/>
<br>
</body>
</html>

2.forEach循环遍历输出集合

2.1 定义自定义标签处理器类

package com.able.tag;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map; import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport; public class ForEachTag extends TagSupport { private String var; private Iterator<?> iterator; public void setItem(Object item) {
if (item instanceof Map) {
Map items = (Map) item;
this.iterator = items.entrySet().iterator();
} else {
Collection<?> c = (Collection) item;
this.iterator = c.iterator();
}
} @Override
public int doStartTag() throws JspException {
if (this.process())
return EVAL_BODY_INCLUDE;
else
return EVAL_PAGE; } @Override
public int doAfterBody() throws JspException {
if (this.process()) {
return EVAL_BODY_AGAIN;
} else {
return EVAL_PAGE;
}
} private boolean process() { if (null != iterator && iterator.hasNext()) {
Object item = iterator.next();
pageContext.setAttribute(var, item);
return true;
} else {
return false;
}
} public String getVar() {
return var;
} public void setVar(String var) {
this.var = var;
}
}

2.3 在tld文件中定义标签

<tag>
<name>foreach</name>
<tag-class>com.able.tag.ForEachTag</tag-class>
<body-content>JSP</body-content> <attribute>
<name>var</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>item</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<!-- <type>java.lang.Object</type> -->
<type>java.util.Collection</type>
</attribute>
</tag>

2.4 在jsp页面定义循环标签

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
List<String> list = new ArrayList<String>();
list.add("aa");
list.add("bb");
list.add("cc");
Map map = new HashMap();
map.put("1","a");
map.put("2","b");
map.put("3","c");
map.put("4","b");
%> <tm:foreach var="hi" item="<%=map %>">
<h1>${hi }</h1>
</tm:foreach>
<br/>
<br>
</body>
</html>

3.定义Iterator循环输出数组

3.1定义标签处理器类

package com.able.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport; public class IteratorTagDemo extends TagSupport {
private String var;
private String[] items; private int i =1;
@Override
public int doStartTag() throws JspException {
if (items != null && items.length>0) {
pageContext.setAttribute("name", items[0]);
return EVAL_BODY_INCLUDE;
} else {
return SKIP_BODY;
}
} @Override
public int doAfterBody() throws JspException {
if (i<items.length) {
pageContext.setAttribute("name", items[i]);
i++;
return EVAL_BODY_AGAIN;
} else {
return SKIP_BODY;
}
} @Override
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
return super.doEndTag();
}
public String getVar() {
return var;
} public void setVar(String var) {
this.var = var;
} public String[] getItems() {
return items;
} public void setItems(String[] items) {
this.items = items;
}
}

3.2 在.tld文件中定义标签

 <tag>
<name>IteratorTagDemo</name><!-- 定义标签名 -->
<tag-class>com.able.tag.IteratorTagDemo</tag-class>
<body-content>scriptless</body-content> <!-- 定义标签体为空 -->
<attribute>
<name>var</name>
<required>true</required>
</attribute>
<attribute>
<name>items</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

3.3在jsp页面定义Tag

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body> <%
String[] nbastar = {"jordan","kobar"};
pageContext.setAttribute("nbastar", nbastar);
%>
<tm:IteratorTagDemo items="${nbastar }" var="name">
${name }
</tm:IteratorTagDemo>
<br/>
<br>
</body>
</html>

4.自定义Tag实现防盗链

4.1自定义标签处理器类

package com.able.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport; public class SkipPageOrEvalPageTag extends TagSupport { @Override
public int doEndTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
String referer = request.getHeader("referer");
String url = "http://"+request.getServerName();
if (referer != null && referer.startsWith(url)) {
return EVAL_PAGE;
} else {
try {
pageContext.getOut().print("盗链");
} catch (IOException e) {
e.printStackTrace();
}
}
return SKIP_PAGE;
}
}

4.2在.tld文件中定义tag标记

<tag>
<name>SkipPageOrEvalPageTag</name><!-- 定义标签名 -->
<tag-class>com.able.tag.SkipPageOrEvalPageTag</tag-class>
<body-content>empty</body-content> <!-- 定义标签体为空 -->
</tag>

4.3定义访问连接的SkipPageOrEvalPageAccess.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 防盗链 -->
<a href="http://localhost/JSP_Tag_Demo/SkipPageOrEvalPage.jsp">防盗链</a>
<br/>
<br>
</body>
</html>

4.4定义访问成功后的SkipPageOrEvalPage.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 防盗链 -->
<tm:SkipPageOrEvalPageTag/>
<h1>SkipPageOrEvalPage标签处理学习</h1>
<br/>
<br>
</body>
</html>

二、使用SimpleTagSupport实现自定义Tag

1.继承SimpleTagSupport类实现循环输出集合或数组

1.1定义标签处理器类

package com.able.simpleTag;

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map; import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport; public class foreachAll extends SimpleTagSupport {
private Object items;
private String var;
private Collection collection;
public void setItems(Object items) {
this.items = items;
if (items instanceof Collection) {//list set
collection=(Collection) items;
}
if (items instanceof Map) {
Map map=(Map) items;
collection =map.entrySet();//set
}
if (items instanceof Object[]) {
Object obj[]=(Object[]) items;
collection=Arrays.asList(obj);
}
if (items.getClass().isArray()) {
this.collection=new ArrayList();
int length=Array.getLength(items);
for (int i=0; i<length ; i++) {
Object value=Array.get(items, i);
this.collection.add(value);
}
}
}
public void setVar(String var) {
this.var = var;
}
@Override
public void doTag() throws JspException, IOException {
Iterator it=this.collection.iterator();
while (it.hasNext()) {
Object value=it.next();
this.getJspContext().setAttribute(var, value);
this.getJspBody().invoke(null); }
}
}

1.2定义.tld文件中添加标签

<tag>
<name>simpleforeachAll</name>
<tag-class>com.able.simpleTag.foreachAll</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>items</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

1.3定义jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
List<String> list = new ArrayList<String>();
list.add("aa");
list.add("bb");
list.add("cc");
Map map = new HashMap();
map.put("1","a");
map.put("2","b");
map.put("3","c");
map.put("4","b");
int arr[]={1,2,3,4,5};
request.setAttribute("arr", arr);
%> <br/>
<br>
<tm:simpleforeachAll var="i" items="${arr }">${i }</tm:simpleforeachAll>
</body>
</html>

2.使用SimpleTagSupport实现防盗链

2.1定义标签处理器类

package com.able.simpleTag;

import java.io.IOException;
import java.sql.Date; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.SkipPageException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class RefererTag extends SimpleTagSupport {
private String site;
private String page;
public void setSite(String site) {
this.site = site;
}
public void setPage(String page) {
this.page = page;
}
@Override
public void doTag() throws JspException, IOException {
PageContext pageContext =(PageContext) this.getJspContext();
HttpServletRequest httpServletRequest=(HttpServletRequest) pageContext.getRequest();
HttpServletResponse httpServletResponse=(HttpServletResponse) pageContext.getResponse();
//1.referer
String referer=httpServletRequest.getHeader("referer");
if (referer==null || !referer.startsWith(site)) {
if (page.startsWith(httpServletRequest.getContextPath())) {
httpServletResponse.sendRedirect(page);
return;
}else if (page.startsWith("/")) {
httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+page);
}else{
httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/"+page);
}
throw new SkipPageException();
}
} }

2.2 定义.tld文件

<tag>
<name>referer</name>
<tag-class>com.able.simpleTag.RefererTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>site</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>page</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

2.3定义refererAccess.jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 防盗链 -->
<a href="http://localhost/JSP_Tag_Demo/Referer.jsp">防盗链</a>
<br/>
<br>
</body>
</html>

2.4定义访问页面referer.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 防盗链 -->
<tm:referer site="" page=""/>
<br/>
<br>
</body>
</html>

三、使用BodyTagSupport实现自定义Tag

1.继承BodyTagSupport实现简单数据输出

1.1定义标签处理器类

package com.able.bodyTag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport; public class BodyTagSupportTag extends BodyTagSupport {
private BodyContent bodyContent; @Override
public int doEndTag() throws JspException {
String content = bodyContent.getString();
System.out.println(content); String newStr = "www.cnblogs.com/izhongwei";
JspWriter jspWriter= bodyContent.getEnclosingWriter();
try {
jspWriter.write(newStr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return EVAL_PAGE;
} public BodyContent getBodyContent() {
return bodyContent;
} public void setBodyContent(BodyContent bodyContent) {
this.bodyContent = bodyContent;
} }

1.2在.tld文件中定义标签

<tag>
<name>bodyTag</name><!-- 定义标签名 -->
<tag-class>com.able.bodyTag.BodyTagSupportTag</tag-class>
<body-content>scriptless</body-content> <!-- 定义标签体为空 -->
</tag>

1.3定义jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- <%@taglib uri="http://www.able.com" prefix="tm" %> --%>
<%-- <%@ taglib prefix="tm" uri="/WEB-INF/tlds/online.tld" %> --%>
<%@taglib prefix="tm" uri="/WEB-INF/tag.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<tm:bodyTag>
hello
</tm:bodyTag>
<br/>
<br>
</body>
</html>

源码下载地址:https://github.com/ablejava/jsp-Tag

git克隆地址:https://github.com/ablejava/jsp-Tag.git  

jsp中自定义Taglib案例的更多相关文章

  1. jsp中的taglib

    JSP中使用Taglib 标准的JSP标记可以调用JavaBeans组件或者执行客户的请求,这大大降低了JSP开发的复杂度和维护量.JSP技术也允许你自定义的taglib,其实换句话说,taglib可 ...

  2. 自定义JSP中的Taglib标签之四自定义标签中的Function函数

    转自http://www.cnblogs.com/edwardlauxh/archive/2010/05/19/1918589.html 之前例子已经写好了,由于时间关系一直没有发布,这次带来的是关于 ...

  3. jsp中 自定义 tag的几种方式

    在jsp文件中,可以引用tag和tld文件. 1.对于tag文件,使用tagdir引用(这个直接是引用的后缀tag文件的jsp文件) <%@ taglib prefix="ui&quo ...

  4. [置顶] JSP中使用taglib出错终极解决办法

    jsp中 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c ...

  5. JSP中使用Taglib

    http://blog.163.com/jany_1016/blog/static/4604400620091112114127341/ http://blog.csdn.net/yuebinghao ...

  6. jsp 中获取自定义变量

    首先确定El表达式的查找范围: 依次从Page.Request.Session.Application 中的 attribute属性中查找. <% String basePath = reque ...

  7. JSP 中的 tag 文件

    在jsp文件中,可以引用 tag 和tld 文件,本文主要针对 tag 对于tag 文件 1)将此类文件放在 WEB-INF 下,比如 /WEB-INF/tags,tags 是目录,其下可以有多个.t ...

  8. jsp中的JSTL与EL表达式用法

    JSTL (JSP Standard Tag Library ,JSP标准标签库) JSTL标签库分为5类:JSTL核心标签库.JSTL函数标签库.数据库标签库.I18N格式化标签库.XML标签库. ...

  9. jsp中c:forEach使用

    首先需要在jsp中引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> ...

随机推荐

  1. samba 服务器的搭建

    一,安装samba4 不要直接 yum install samba ,默认安装的是samba3版本,但这个版本有问题(open_rpc_pipe_p: copy_serverinfo failed这个 ...

  2. ci配置smarty手记

    需要用ci来写一个后台配置smarty,在网络上能够找到一些相关的文章.但是都是比较旧的内容,大部分是smary2.*的配置方法.按照这个配置后会出现一些错误.其实配置看smary官方会比较简单. 基 ...

  3. Unitils集成DBUnit的问题-解决方案

    Unitils在集成DBunit时,如果数据库是mysql时,就会出现一些如下: org.unitils.core.UnitilsException: Error inserting test dat ...

  4. IPv4分析

    IPv4的头部格式: 1. Version 版本号,默认是4. 2. IHL(Internet Header Length) 就是IPv4头部长度.这个长度的单位是32bit,一般是5,那么头部的长度 ...

  5. 一个基于POP3协议进行邮箱账号验证的类

    最近老陈要针对企业邮箱做一些开发,以对接企业OA神马的,但企业邮箱唯独没有开放账号密码验证功能,很恼火!不得已,翻出早些年的Asp代码改编成了C#类,实现了一个C#下的通过POP3协议进行邮箱账号验证 ...

  6. [Linux] 查看系统启动时间

    查找系统最后启动时间 1. 使用 who 命令 who -b 输出: system boot 2015-10-14 00:51 2. 使用 last 命令 last reboot | head -1 ...

  7. 403 Forbidden client denied by server configuration[apache2, linux]

    在LAMP的配置过程中, 由于APACHE的版本问题, 即使是APACHE2和APACHE2.2也有很大的不同. 一般都有同一个环境配置多个虚拟网站的情况, 如果你在配置过程中遇到APACHE的不同版 ...

  8. Enjoy Android

    大趋势所迫,开始学习Android, @mark一下

  9. 菜鸟学Windows Phone 8开发(1)——创建第一个应用程序

    本系列文章来源MSDN的 面向完全新手的 Windows Phone 8 开发 主要是想通过翻译本系列文章来巩固下基础知识顺带学习下英语和练习下自己的毅力(因为打算每天翻译一篇,但是发现翻译这篇花费了 ...

  10. DDD:订单管理 之 如何组织代码

    背景 系统开发最难的是职责的合理分配,或者叫:“如何合理的组织代码”,今天说一个关于这方面问题的示例,希望大家多批评. 示例背景 参考数据字典 需求 OrderCode必须唯一. Total = Su ...