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

  • SEARCH
  • Home
  • 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 612175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:51:53+00:00 2026-05-13T17:51:53+00:00

First I have a Spring 3.0 controller with a method similar to the following.

  • 0

First I have a Spring 3.0 controller with a method similar to the following.

I’m passing the view an object named “message” and hoping to print that message via the view if it has been set by the “doStuff” method.

@RequestMapping("/index")
public ModelAndView doStuff() {
    ModelAndView mav = new ModelAndView();
    Map<String, String> message = new HashMap<String, String>();
    message.put("message", "Hello World");
    mav.setViewName("pages/myView");
    mav.addObject("message", message);
    return mav;
}

The view is similar to the following,

<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
<head>
<title>Test</title>
</head>
<body>
<c:if test="${message.message} != null">
    <div class="msg">test1: ${message.message}</div>
</c:if>
<c:if test="${message.message} != ''">
    <div class="msg">test2: ${message.message}</div>
</c:if>
<c:if test="${message.message}">
    <div class="msg">test3: ${message.message}</div>
</c:if>
<c:if test="not empty ${message.message}">
    <div class="msg">test4: ${message.message}</div>
</c:if>
<div class="msg">test5: ${message.message}</div>
</body>
</html>

So far, only “test5” is printing the message, but I only want to print the message if “${message.message}” is not null.

I’ve tried both “http://java.sun.com/jstl/core_rt” and “http://java.sun.com/jstl/core“, but can’t seem to get the “<c:if />” statements to work correctly.

Would anyone have any ideas as to what I’m doing wrong or a better way to do it?

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-13T17:51:53+00:00Added an answer on May 13, 2026 at 5:51 pm

    Your first two <c:if> tags should look like this:

    <c:if test="${message.message != null}">
        <div class="msg">test1: ${message.message}</div>
    </c:if>
    <c:if test="${message.message != ''}">
        <div class="msg">test2: ${message.message}</div>
    </c:if>
    

    Note the placement of the != and the } in the test attribute — the condition needs to be inside the braces.

    also, the test in #3:

    <c:if test="${message.message}">
        <div class="msg">test3: ${message.message}</div>
    </c:if>
    

    Will only evaluate to true if the value of the message.message is in fact the value “true”. Since it is not (it is “Hello World”), the test fails.

    Test #4 is also formatted incorrectly (the “not empty” also needs to be inside the braces)…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.