Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6082987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:21:01+00:00 2026-05-23T11:21:01+00:00

In my Struts2 project returned a List<Object> from my java action class. One of

  • 0

In my Struts2 project returned a List<Object> from my java action class. One of the data members in the objects is a date in long form (from MySQL database). I am not authorised to make changes to the class structure or database. I need to output this date as human readable.
I want to implement:

<% Date mydate = new Date (long dateAsLong); %>
<%= mydate.toString() %>

Here dateAsLong is data member of the objects returned.
I need this help as I have to apply it to other cases as well. Like I have to check the variables in JSP itself using:

<s:if test='<s:property value="priority"/> == 1'>
  /*Some img to display here*/
</s:if>

I am a newbie and want to use plain struts2 and JSP. Please just help me know how I can access that variable returned in <s:property/>.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:21:01+00:00Added an answer on May 23, 2026 at 11:21 am

    The <s:set/> tag places values on to the ValueStack, which isn’t conveniently available from scriptlets (I would recommend you avoid scriptlets anyway).

    First, on the subject of:

    <s:if test='<s:property value="priority"/> == 1'>
      /*Some img to display here*/
    </s:if>
    

    Try this:

    <s:if test="%{priority == 1}">
      /*Some img to display here*/
    </s:if>
    

    You can also use JSP EL:

    <c:if test="${action.priority == 1}">
      /*Some img to display here*/
    </c:if>
    

    As for the date, asdoctrey mentioned, you could do this conversion in your action class. I’ve handled this in the past using a custom JSP function.

    The TLD

    <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><![CDATA[JSP Functions]]></description>
      <display-name>JSP Functions</display-name>
      <tlib-version>1.0</tlib-version>
      <short-name>ex</short-name>
      <uri>http://www.example.com/tags/jsp-functions</uri>
    </taglib>
    

    The Java

    /**
     * The JSTL fmt:formatDate tag expects a Date and the fmt:parseDate
     * apparently expects to parse from a String representation of the
     * date. This method allows you to easily convert a long into a Date
     * object for use in fmt:formatDate.
     * <p/>
     * The long passed in to this method is expected to be a UNIX epoch
     * timestamp (number of milliseconds since Jan. 1, 1970). For more
     * details, see {@link java.util.Date#Date(long)}.
     *
     * @param epoch The long to convert. Expected to be an epoch timestamp.
     * @return A new Date object.
     */
    public static Date longToDate(final long epoch) {
      return new Date(epoch);
    }
    

    The JSP

    <%@ taglib prefix="ex" uri="http://www.example.com/tags/jsp-functions" %>
    
    ${ex:longToDate(action.dateAsLong)}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project which uses Java,MySql,Struts2 MVC and Hibernate. I tried
I want to develop my project on Google App Engine with Struts2. For the
I am developing project using Spring , Struts2 & Hibernate . Now I want
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
The struts2 validation framework allows you to define your validation for an action or
Scenario: A fairly mature project uses Struts2 and Spring and Hibernate. I say mature
I am starting a project on Struts2 which also includes JPA, Postgres, Jquery and
My Web-program config is Struts2 and Tomcat 6.0. and my project is support i18n(International~)
I have just moved from phase 1 to phase 2 of a project. In
I have just started working on a struts2 project. I have seen the power

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.