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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:16:30+00:00 2026-05-26T01:16:30+00:00

I wonder if anyone could give me a pointer with some pre-population in JSP:

  • 0

I wonder if anyone could give me a pointer with some pre-population in JSP:

So I am attempting to pre-populate a checkbox depending on the value in the customers database record. The checkbox would be checked if there is a 1 in the field, the other option would be a 0 – where the checkbox should be empty.

I am currently using this code within the input:

<%if (UPDATEDPREFERENCES != null)
{ 
    if (ISNEWSLETTER != "0") {
        out.println("checked");
    } 
}
%>

so it would be:

<input type='checkbox' class="newsletter" name='temp_ISNEWSLETTER_FIELD' id="temp_ISNEWSLETTER_FIELD" <%if (UPDATEDPREFERENCES != null)
{ 
    if (ISNEWSLETTER != "0") {
        out.println("checked");
    } 
}
%>/>

As it stands, it pre-populates fine. However, it also populates if the field is 0. If I change it to read:

if (ISNEWSLETTER == "1")

then the checkbox is empty whether it’s a 1 or 0.

Am I missing something obvious? I am not a developer, I am in NYC and my support is in Belgium – they’ve all left for the day.

  • 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-26T01:16:31+00:00Added an answer on May 26, 2026 at 1:16 am

    Strings are objects, not primitives. Use equals(), not ==/!=. The ==/!= won’t check if they contain the same value, but if they point to the same object reference. The equals() will check if they contain the same value.

    So, instead of if (ISNEWSLETTER != "0") you should use

    if (!ISNEWSLETTER.equals("0"))
    

    and instead of if (ISNEWSLETTER == "1") you should use

    if (ISNEWSLETTER.equals("1"))
    

    This problem is not related to JSP. You would have exactly the same problem when doing so in a normal Java class (where this kind of code actually belongs).

    As an alternative, since they represent numbers, you could also just convert ISNEWSLETTER to an int. It’s a primitive, so you should be able to use ==/!= the usual way. You can if necessary convert a String to an int using Integer#parseInt(). Or, even more, if it actually represents a boolean state (it can only be true or false), then you should rather use boolean instead. You can just use it straight in the if condition without any need for comparisons.

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

Sidebar

Related Questions

I wonder if anyone could offer their advice on this one. I have some
Wonder if anyone could shed some light on this http://jsfiddle.net/orbitalmedia/ZrxBb/7/ Basically I'm trying to
Hi I wonder if anyone could give me an example how the TickGetDiv256(); function
I wonder if anyone could suggest the best way of looping through all the
I wonder if anyone could help me with a problem I've been having. I
I wonder if anyone can help me to understand where I could be going
I wonder if anyone could point me in the direction where I can read
I wonder if anyone could help me. I have a web page where there
I wonder if anyone knows how could I rename multiple files, all of them
I have a question regarding AS3 memory management I wonder if anyone could help

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.