易截截图软件、单文件、免安装、纯绿色、仅160KB

jsp自定义标签(tag)开发

1 标记处理程序类
处理类继承TagSupport类并重载doStartTag()方法,
       在该方法中使用out.print();输出需要的数据到使用本标签的jsp页面
package cn.xxx;
public class DateTag extends TagSupport {
private static final long serialVersionUID = 1L;
public int doStartTag() throws javax.servlet.jsp.JspException {
JspWriter out;
try {
out = pageContext.getOut();
out.print("hello你好" + new Date());
} catch (IOException ioe) {
throw new JspException("I/O Error : " + ioe.getMessage());
}
return Tag.SKIP_BODY;//return 0;
}

2 创建使用标签类的创TLD文件
(可以从struts中的标签库中的tld复制)
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
web-jsptaglibrary_2_0.xsd" verson="2.0">

<tlib-version>1.0</tlib-version>
<jspversion>1.1</jspversion>

<info>A simple tag library</info>
<tag>
<name>displayDate</name>
<tagclass>cn.eecn.DateTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Display Date</info>
</tag>
</taglib> 
3 导入标签库
    * 方法1
          在web.xml文件中先静态导入tld文件,再jsp中用别名导入标签
web.xml:
<taglib>
<taglib-uri>myTags</taglib-uri>
<taglib-location>/WEB-INF/lib/DateTagLib.tld</taglib-location>
</taglib> 
jsp:
<%@ taglib uri="myTags" prefix="abc" %> 
* 方法2:
        在jsp页面中直接使用动态导入tld文件
<%@ taglib uri="/WEB-INF/lib/DateTagLib.tld" prefix="abc" %> 
4 在页面中使用标签
    jsp
<abc:displayDate /> 
引用参考:http://blog.myspace.cn/e/406226695.htm


相关文档:

纯JSP分页代码之Mysql

//运行图:
//连接字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName(driverName).newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
//每页显示记录数
int PageSize ......

jsp生成xml文件示例

<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java"%>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%> ......

Jsp的九种对象

Jsp的九种对象我简述之:
page
application
request
response
session
config
out
pageContext
 
page
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
response
<%
  response.setHeader("Pragma","No-cache"); 
  respons ......

jsp连接mysql对数据库进行操作乱码的解决


如果jsp插入mysql数据库出现乱码,mysql数据库安装时编码设为utf8,在执行插入语句的前面(紧挨着执行语句)添加转码语句:String na="";
                  try{
          &nbs ......

jsp页面div应用

<%@ page contentType="text/html;charset=GBK"%>
<div id="divDisable" style="display: none;width:expression(document.body.offsetWidth); height:100%; z-index: 1000; position: absolute;left: 0px; top: 0px;filter:alpha(opacity=50); background-color:White">
</div>
<div id="divWaiti ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号