- 爱易网页
-
JavaSript
- 自定Jsp标签-功课-日期输出转换
日期:2014-05-16 浏览次数:20522 次
自定Jsp标签---作业--日期输出转换
package com.hbsi.web.tag;
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;
import javax.servlet.jsp.tagext.Tag;
public class ViewTMTag extends BodyTagSupport {
@Override
public int doEndTag() throws JspException {
BodyContent bc = this.getBodyContent();
String b = bc.getString();
String[] data = b.split("-");
JspWriter out = this.pageContext.getOut();
try {
out.println("年:"+data[0]+"<br>");
out.println("月:"+data[1]+"<br>");
out.println("日:"+data[2]+"<br>");
} catch (IOException e) {
e.printStackTrace();
}
return Tag.EVAL_PAGE;
}
}
<?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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>A tag library exercising SimpleTag handlers.</description>
<tlib-version>1.0</tlib-version>
<short-name>hbsi</short-name>
<uri>http://www.hbsi.com</uri>
<tag>
<name>viewIP</name>
<tag-class>com.hbsi.web.tag.ViewIPTag</tag-class>
<body-content>empty</body-content>
</tag>
<tag>
<name>ViewTM</name>
<tag-class>com.hbsi.web.tag.ViewTMTag</tag-class>
<body-content>JSP</body-content>
</tag>
</taglib>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.hbsi.com" prefix="hbsi" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DT
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。