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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:13:50+00:00 2026-06-14T08:13:50+00:00

my problem i am not get array from jquery post to jspservlet is shows

  • 0

my problem i am not get array from jquery post to jspservlet is shows nullpointer exception always.my jsp page code is listed below :

<!DOCTYPE html>
<html>
<head>
<script src="JS/jquery-latest.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
      $("p").fadeToggle(3000,function(){
          var fields=new Array();

          fields = $(":input").serializeArray();
          $.post("exampleservlet",{arraydata:fields,mode:"Insert"},
          function(data) {
                alert("Data Loaded: " + data);
          });      
      });
      return false;
  });
});
</script>
</head>
<body>
    <form>
        <input type="text" name="txt_name" />
        <input type="text" name="txt_name1" />
        <input type="text" name="txt_name2" />
        <input type="text" name="txt_name3" />
      <p style="background:blue;color:white;padding:10px;">If you click on me, I will disappear.</p>
        <button>Click me</button>
    </form>   
</body>
</html>

and my jsp servlet java code listed below:

@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String jsresponse="No Message";

       try
        {
        String arrayData[] = request.getParameterValues("arraydata");
        //String data[]=request.getParameterValues("arraydata[]");

        jsresponse = arrayData[0] +" - ";//"This line shows null pointer exception!";

        }
        catch(Exception ex)
        {

        }


        response.setContentType("text/plain");  // Set content type of the response so that jQuery knows what it can expect.
        response.setCharacterEncoding("UTF-8"); // You want world domination, huh?
        response.getWriter().write(jsresponse);
    }

and i am getting null pointer exception on this line

jsresponse = arrayData[0];//"This line shows null pointer exception!";

it’s shows error log like below:

Nov 15, 2012 4:10:03 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [exampleservlet] in context with path [/javaservletwithajax] threw exception
java.lang.NullPointerException
    at com.example.servlets.exampleservlet.doPost(exampleservlet.java:56)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

any one help with me how to get array from dopost parameter values in jsp servlet!

Solved My Problem from kmb385 like below:

Changes in jquery

$(document).ready(function(){
  $("button").click(function(){
      $("p").fadeToggle(3000,function(){

           var fields=new Array();
           var values = new Array();

           fields = $(":input").serializeArray();
           $.each(fields, function(index,element){
             values.push(element.value);
           });

          $.post("exampleservlet",{arraydata:values,mode:"Insert"},
          function(data) {
                alert("Data Loaded: " + data);
          });

      });
      return false;
  });
});

Changes in jsp servlet:

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String jsresponse="No Message";

   try
    {
    String arrayData[] = request.getParameterValues("arraydata[]");
    //String data[]=request.getParameterValues("arraydata[]");
    jsresponse = arrayData[0] +" - ";//"Test Response!";

    }
    catch(Exception ex)
    {
     jsresponse = ex.toString();               
    }
    response.setContentType("text/plain");  // Set content type of the response so that            jQuery knows what it can expect.
    response.setCharacterEncoding("UTF-8"); // You want world domination, huh?
    response.getWriter().write(jsresponse);
}

it’s works cool!

  • 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-14T08:13:51+00:00Added an answer on June 14, 2026 at 8:13 am

    There are two issues being encountered.

    1. Brackets must be specified in the String literal used to retrieve the parameter values.
    2. An array is not being passed over the wire to the servlet.

    To solve the first issue, change the argument passed to getParameterValues

    String arrayData[] = request.getParameterValues("arraydata[]");
    

    To solve the second issue, you must iterate through the objects returned by Jquery’s serializeArray method and construct an array of the values. The objects returned by serializeArray are in the form {name:val, value: val}. Use the following code to create and pass this array:

     var fields=new Array();
       var values = new Array();
    
       fields = $(":input").serializeArray();
       $.each(fields, function(index,element){
         values.push(element.value);
       });
    
      $.post("exampleservlet",{arraydata:values,mode:"Insert"},
      function(data) {
            alert("Data Loaded: " + data);
      });
    

    Prior to this change the request you posted looked like this going across the wire:

    enter image description here

    After the change it uses a single dimension array, looking like:

    enter image description here

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

Sidebar

Related Questions

I have a little problem. i searched but did not get help to solve
Seem to run into a service endpoint not found problem when trying to get
I get a weird problem. Getting java.util.ConcurrentModificationException . But I'm not modifying the current
I have a problem with: NHibernate.Cfg.Configuration.SetProperties() Not accepting the IDictionary: NHibernateConfigHandler I get the
I'm trying to get a FacebookLoginTest running. Problem is: the Symfony2 client does not
I'm building a list of items in jQuery mobile from an array, and paginating
I'm building up a function in jQuery that populate an array from an XML.
The problem I am having is that my jquery script is not returning the
According to my previous post I am trying to get back some information from
In my previous post i ask how to create variables from an array (

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.