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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:05:28+00:00 2026-05-24T01:05:28+00:00

This is more of a logic question. I have a checkbox on a webpage

  • 0

This is more of a logic question. I have a checkbox on a webpage and I store its value from the servlet request parameters in a Boolean object (Java). The logic is, if the request parameter for the checkbox is not null, make the object true, otherwise it’s null. When the page is called again, it marks the checkbox as “checked” if its stored value is true.

this.checkbox = (servlet.getParameter("checkbox")!=null && servlet.getParameter("checkbox").contentEquals("on"))?true:null;

The problem starts when I persist that checkbox object. I first populate the page with the persisted data and then fill it with the servlet values. If the checkbox value is stored as true in the database, and the user unchecks it on the page and submits it, since the servlet parameter for the checkbox becomes null, I am unable to make the checkbox null. So the checkbox always show the persisted value since its never gets overwritten. So can anyone suggest some logic change in how I am filling the object value?

  • 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-24T01:05:29+00:00Added an answer on May 24, 2026 at 1:05 am

    The only valid test for checkbox is to see whether getParameter() returns null or not.

    If the return value is null it’s unchecked, otherwise it’s checked.

    Note, that checked attribute should be present if you want the checkbox be checked on the first page presentation and should not be present at all if you want it unchecked. The parameter value should always be checked, as in the example below.

    <label>
      <input
        type="checkbox" 
        id="cb_id"
        name="cb_id"
        value="cb_id_value"
        checked="checked"
      />
      My label
    </label>
    

    For this example, you may have this logic in your servlet processing code:

    HTTPServetRequest request = ...;
    
    boolean cbState = request.getParameter( "cb_id" ) != null;
    

    Note, that if the checkbox is checked by the user in the above example getParameter will return "cb_id_value", but because you usually have a single checkbox with a dedicated name you don’t have to check the value.

    BTW, I’ve noticed in your example that you are using servlet to getParameter. I hope that in your system it is a moniker for HTTPServletRequest.

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

Sidebar

Related Questions

This is more of a design question. I have a template class, and I
This is more of a logic question than a coding question. I am building
Ok this is more of general technology/approach question. We have a very simple web
This is more a question of curiosity. So I was reading a chapter from
This question is more logic than programming at the moment.. once I understand what
I have seen this question, and have some more doubts regarding creating a jar
Ok, I'm going to try to make this more clear because my last question
I have a label on my asp.net page, it looks like this: more info
This is more of a hypothetical question. I am wondering if anyone knows if/how
This is more of an architectural and security question than anything else. I'm trying

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.