JSTL格式化库

来源:互联网 发布:cs fps优化 编辑:程序博客网 时间:2024/03/29 01:20
 

JstlFmtAction.java

public class JstlFmtAction extends Action {
 public ActionForward execute(ActionMappingmapping, ActionForm form,
   HttpServletRequestrequest, HttpServletResponse response)
   throwsException {
  request.setAttribute("today",new Date());
  
  request.setAttribute("n",123456.123);
  
  request.setAttribute("p",0.12345);
  returnmapping.findForward("success");
 }
 jstl_fmt.jsp

 

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

<h1>测试jstl格式化库</h1>
 <hr>
 <li>测试日期的格式化</li><br>
 today(default):<fmt:formatDatevalue="${today}"/><br>
 today(type="date"):<fmt:formatDatevalue="${today}"type="date"/><br>
 today(type="time"):<fmt:formatDatevalue="${today}"type="time"/><br>
 today(type="both"):<fmt:formatDatevalue="${today}"type="both"/><br>
 today(dateStyle="short"):<fmt:formatDatevalue="${today}"dateStyle="short"/><br>
 today(dateStyle="medium"):<fmt:formatDatevalue="${today}"dateStyle="medium"/><br>
 today(dateStyle="long"):<fmt:formatDatevalue="${today}"dateStyle="long"/><br>
 today(dateStyle="full"):<fmt:formatDatevalue="${today}"dateStyle="full"/><br>
 today(pattern="yyyy/MM/ddHH:mm:ss"):<fmt:formatDate value="${today}"pattern="yyyy/MM/ddHH:mm:ss"/><br>
 today(pattern="yyyy/MM/ddHH:mm:ss"):<fmt:formatDate value="${today}"pattern="yyyy/MM/dd HH:mm:ss"var="d"/><br>
 ${d }<br>
 <p>
 <li>测试数字的格式化</li><br>
 n(default):<fmt:formatNumbervalue="${n}"/><br>
 n(pattern="###,###.##"):<fmt:formatNumbervalue="${n}"pattern="###,###.##"/><br>
 n(pattern="###,###.0000"):<fmt:formatNumbervalue="${n}"pattern="###,###.0000"/><br>
 n(groupingUsed="false"):<fmt:formatNumbervalue="${n}"groupingUsed="false"/><br>
 n(minIntegerDigits="10"):<fmt:formatNumbervalue="${n}"minIntegerDigits="10"/><br>
 n(type="currency"):<fmt:formatNumbervalue="${n}"type="currency"/><br>
 n(type="currency"):<fmt:formatNumbervalue="${n}" type="currency"currencySymbol="$"/><br>
 n(type="percent"):<fmt:formatNumbervalue="${p}" type="percent" maxFractionDigits="2"minFractionDigits="2"/><br>