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 6831121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:42:00+00:00 2026-05-26T22:42:00+00:00

I’m not sure if I can do this, but I’m trying to print a

  • 0

I’m not sure if I can do this, but I’m trying to print a string with Expression Language only (no JSTL). The string is going to often-times be null, and I want an empty string printed to HTML instead of the word “null”. This is what I’m trying (without success):

<%
  myString = "";
  myString = someMethodThatMayReturnNull(); // returns string or null
%>
<b>${myString}</b><br />
<b>${ (empty myString) ? "myString-is-empty" : "myString-is-NOT-empty" }</b><br />

The reason I don’t want to use JSTL is because I’m trying to make the minimum changes to a fairly good sized system.

  • 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-26T22:42:00+00:00Added an answer on May 26, 2026 at 10:42 pm

    Scriptlets and EL doesn’t share the same variable scope. You need to prepare EL variables as attributes of page, request, session or application scope. As you have right now, it is always empty.

    <%
      myString = "";
      myString = someMethodThatMayReturnNull(); // returns string or null
      request.setAttribute("myString", myString); // It's now available by ${myString}
    %>
    

    Note that you normally do that Scriptlet part inside a Servlet. Also note that EL is null-safe, so anything which is truly null, i.e. if (object == null) passes, then it simply won’t be printed at all.

    Or, if your concrete problem is that it prints literally ${myString} and so on in the browser, while it worked with JSTL <c:out>, then it means that you aren’t using a JSP 2.0 compatible servletcontainer or that your webapp’s web.xml is not declared conform at least Servlet 2.4, or that you have isElIgnored set to true. Verify and fix it all.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string

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.