当前位置: 代码迷 >> JavaScript >> 自定Jsp标签-功课-日期输出转换
  详细解决方案

自定Jsp标签-功课-日期输出转换

热度:412   发布时间:2012-11-22 00:16:41.0
自定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//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>转换日期格式并输出</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>  
    <hbsi:ViewTM>2012-11-17</hbsi:ViewTM>  
  </body> 
  
</html>
  相关解决方案