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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:06:23+00:00 2026-06-04T01:06:23+00:00

I am calling a servlet from JavaScript with request parameters but the servlet is

  • 0

I am calling a servlet from JavaScript with request parameters but the servlet is not getting called.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<title>Test</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
</style>
</head>
<body>
  <table border="1" cellpadding = "15">
    <tr><td>1</td><td>2</td><td>3</td></tr>
    <tr><td>4</td><td>5</td><td>6</td></tr>
    <tr><td>7</td><td>8</td><td>9</td></tr>
  </body>
</table>
<script>
$('td').click(function(){
    var colIndex = $(this).parent().children().index($(this));
    var rowIndex = $(this).parent().parent().children().index($(this).parent());
    alert('Row: ' + rowIndex + ', Column: ' + colIndex);
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://localhost:8080/TestFinalWebApp/MyServlet?rowIndex=' + rowIndex + "&colIndex=" + colIndex, true);
    xhr.send(null);
});
</script>
</body>
</html>

This is the deployment descriptor:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
    <servlet-name>GetParameters</servlet-name>
    <servlet-class>com.example.web.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>GetParameters</servlet-name>
    <url-pattern>/MyServlet</url-pattern>
</servlet-mapping>  
</web-app>

EDIT:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String rowIndex = request.getParameter("rowIndex");
        String colIndex = request.getParameter("colIndex");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.print("rowIndex:" + rowIndex + "  colIndex:" + colIndex);
    }

Can you please tell me why the servlet is not getting called?

  • 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-04T01:06:24+00:00Added an answer on June 4, 2026 at 1:06 am

    Some comments:

    1. Since you already include jQuery, use the ajax() function. It has much better error handling and solves many corner cases for you.

    2. Update to a more recent version of jQuery. The latest release is 1.7.2.

    3. localhost will only work if the server is on the same machine as the browser. OK during development but will break when you deploy. Either get rid of it (then the browser will prepend it for you) or make sure the URL is generated from the servlet context.

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

Sidebar

Related Questions

How to get the data from ajax request in servlet page. Here I'm calling
I am calling a servlet from GWT client code using RequestBuilder. In the request
Calling Html.RenderPartial(~/Views/Payments/MyControl.ascx); from a view works if MyControl.ascx is a control that directly inherits
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
Is calling HttpServletResponse.addCookie(); (from servlet-api-2.5) multiple times using a cookie with the same name
I have a servlet that is called from a link on another page. The
I am calling a Servlet from index.jsp using Ajax. If the result is false,
I am calling a Java servlet from my Java file. The servlet file has
I am using a servlet that is taking parameters from a registration form, what
I'm experimenting with sending data from a jsp form and calling a servlet and

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.