在JSTL / JSP中,给定java.util.Date,我如何找到第二天?

编程入门 行业动态 更新时间:2024-10-26 04:30:38
本文介绍了在JSTL / JSP中,给定java.util.Date,我如何找到第二天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在JSTL / JSP页面上,我的应用程序中有一个java.util.Date对象。我需要在该对象指定的日期之后找到的那一天。我可以使用< jsp:scriptlet>放入Java并使用java.util.Calendar进行必要的计算,但这对我来说感觉笨拙和不优雅。

On a JSTL/JSP page, I have a java.util.Date object from my application. I need to find the day after the day specified by that object. I can use <jsp:scriptlet> to drop into Java and use java.util.Calendar to do the necessary calculations, but this feels clumsy and inelegant to me.

有没有办法使用JSP或JSTL用标签实现这一目标而不必切换到全面的Java,或者后者是实现这一目标的唯一方法吗?

Is there some way to use JSP or JSTL tags to achieve this end without having to switch into full-on Java, or is the latter the only way to accomplish this?

推荐答案

我不喜欢将java代码放入你的jsp。

I'm not a fan of putting java code in your jsp.

我使用静态方法和taglib来实现这一点。

I'd use a static method and a taglib to accomplish this.

尽管我的想法。有很多方法可以解决这个问题。

Just my idea though. There are many ways to solve this problem.

public static Date addDay(Date date){ //TODO you may want to check for a null date and handle it. Calendar cal = Calendar.getInstance(); cal.setTime (date); cal.add (Calendar.DATE, 1); return cal.getTime(); }

functions.tld

functions.tld

<?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="java.sun/xml/ns/j2ee" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="java.sun/xml/ns/j2ee java.sun/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <description>functions library</description> <display-name>functions</display-name> <tlib-version>1.1</tlib-version> <short-name>xfn</short-name> <uri>yourdomain/functions.tld</uri> <function> <description> Adds 1 day to a date. </description> <name>addDay</name> <function-class>Functions</function-class> <function-signature>java.util.Date addDay(java.util.Date)</function-signature> <example> ${xfn:addDay(date)} </example> </function> </taglib>

更多推荐

在JSTL / JSP中,给定java.util.Date,我如何找到第二天?

本文发布于:2023-11-27 01:56:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第二天   JSP   JSTL   java   Date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!