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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:09:54+00:00 2026-06-15T23:09:54+00:00

I have a JSP file in which jQuery is supposed to send a POST

  • 0

I have a JSP file in which jQuery is supposed to send a POST request containing the elements (categories) I have ticked in a multi select box to the server. The server will analyse the string containing all ticked categories and return a list of subjects, for the jQuery to analyse it and display the subjects in another multi select.

The only problem is, when I tick no category, the jQuery does send an empty parameter to the server, but the server never detects it as null!

I tried an alert that does display “”, but it just won’t work! The server crashes pretexting a NullPointerException related to the code in the if condition obviously.

Here’s my code:

 === JSP ===

<script>
                $(document).ready(function ()  
                    {
                        $('#subjectCategories').change(function()
                            {
                                var selectedOptions = $('#subjectCategories option:selected');
                                var selectedValues = $.map(selectedOptions ,function(option) 
                                {
                                    return option.value;
                                }).join(',');

                                $.ajax({
                                       type: "POST",
                                       url: "creation",
                                       data: 'selectedSubjectCategories='+selectedValues,
                                       success: function(data)
                                       {
                                           if (data!=null)
                                            {
                                                   //alert("\""+data+"\"");
                                                   var subjects = data.split(',');
                                                   var select = $('#subjectslist');
                                                    $('#subjectslist').children().remove();
                                                   $.each(subjects, function(key, subject) 
                                                   {
                                                       if (select.find('option[value="' + subject + '"]').length === 0 && subject!="") 
                                                       {
                                                             //Ajouter la nouvelle catégorie dans la liste
                                                               $('<option>', {
                                                                 value: subject,
                                                                 text: subject
                                                                 }).appendTo(select);
                                                       }
                                                   });
                                            }
                                           else
                                            {
                                                $('#subjectslist').children().remove();
                                            }
                                       }
                                     });
                            }
                        );
                    }).change();
              </script>

=== SERVLET ===

            if (request.getParameter("selectedSubjectCategories")!=null)
        {
            String[] categoryList = request.getParameter("selectedSubjectCategories").split(",");

            ArrayList<String> pourDoublons = new ArrayList<String>();
            String subjectsToShow = new String();

            for (int i=0; i<categoryList.length; i++)
            {
                if (categorySubjectsHashMap.containsKey(categoryList[i]))
                {
                    ArrayList<String> subjectsOfCategory = categorySubjectsHashMap.get(categoryList[i]);
                    for (int j=0; j<subjectsOfCategory.size(); j++)
                    {
                        if (!pourDoublons.contains(subjectsOfCategory.get(j)))
                        {
                            subjectsToShow += subjectsOfCategory.get(j)+",";
                            pourDoublons.add(subjectsOfCategory.get(j));
                        }
                    }
                }
            }
            categoryList = null;
            pourDoublons = null;
            response.setContentType("text/plain");  
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write(subjectsToShow.substring(0,subjectsToShow.length()-1));
        }
        else
        {
            response.setContentType("text/plain");  
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("");
        }

Why can’t my parameter be detected as null? I also tried .equals(null) and a lot of stuff like that, but nothing worked! 🙁

Thanks in advance.

  • 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-06-15T23:09:56+00:00Added an answer on June 15, 2026 at 11:09 pm
    if (request.getParameter("selectedSubjectCategories")!='')
    

    worked fine. 🙂

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

Sidebar

Related Questions

I have a .jsp file that receives a request and checks the request's parameters.
I have the following in jsp: <form action=/ucReady2/uploadservlet method=post enctype=multipart/form-data> <label for=filename_1>File: </label> <input
I have a jsp file which calls another jsp file opening it as a
I have a JSP file which creates an Excel document. I want to dynamically
I have a JSP file Signup.jsp which submits to UserDetails servlet which inserts the
I have a JSP file, member.jsp which is as follows : <%@ page import=java.util.*
I have following piece of code in my jsp file which getSession information: <jsp:useBean
I have a a JSP file in this format(two select tags)- <%@ page import=mypackage.*
I have a jsp file which contain javascript functions at top of file. These
I have created a child.jsp file which has a button named Continue. I have

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.