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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:52:23+00:00 2026-05-11T21:52:23+00:00

I do have a communication problem here between my Java servlet and an Ajax

  • 0

I do have a communication problem here between my Java servlet and an Ajax request. more about it:

Absolute path to the index.html (including JavaScript/Ajax request):
http://localhost:9080/chat/index.html

In the same folder the servlet:
MyChat.class

And the Request is working like this:

var url = "http://localhost:9080/chat";

var name = document.getElementById("username").getAttribute("value");
var message = document.getElementById("message").getAttribute("value");

var tosend = name+","+message;

request.open('GET', url, true);
request.send(tosend);
request.onreadystatechange = interpretRequest;

I’m having a formula where a user just types in the name and the message and username and message are <input> tags in my HTML file. The Ajax request works, that’s sure, but it doesn’t communicate with the servlet. I also don’t have an idea where the output from System.out.println() goes. No log file is filled… And the servlet looks like this:

public class MyChat extends HttpServlet
{
    private static final long serialVersionUID = 1L;
    
    private ArrayList<String> myMessages = new ArrayList<String>();
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                        throws IOException, ServletException
    {
        BufferedReader r = request.getReader();

        while(r.readLine() != null)
        {
                        // split the words at the ','
            String[] tmp = r.readLine().split(".\\s");
            myMessages.add(tmp[0]+" "+tmp[1]);
        }
                
        //response.setContentType("text/html");
        PrintWriter out = response.getWriter();

                Iterator<String> it = myMessages.iterator();
        while(it.hasNext())
        {
            out.println(it.next());
                        System.out.println(it.next());
        }
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                        throws IOException, ServletException
    {
        doGet(request, response);
    }
}
  • 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-11T21:52:23+00:00Added an answer on May 11, 2026 at 9:52 pm

    The URL you’ve specified isn’t to your servlet.

    Just like the URL to the index page is http://<server>:<port>/<webapp name>/<resource> the URL to your servlet needs a mapping in the web.xml file that corresponds to the <resource> part of the url.

    For example, if you had a controller servlet you’d expect something like the following in your web.xml:

    <servlet>
      <servlet-name>controller</servlet-name>
      <servlet-class>ControllerServlet</servlet-class>
    </servlet>
    
    <servlet-mapping>
      <servlet-name>controller</servlet-name>
      <url-pattern>/*.do</url-pattern>
    </servlet-mapping>
    

    The URLs that would invoke the ‘controller’ servlet would then follow the form http://<server>:<port>/<webapp name>/<anything>.do.

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

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

Folks, For the n-th time in a row, i'm hitting the same old problem
Long speech short: How can I make hundreds of simultaneously running processes communicate with
I was asked to manage and develop a project. The client does not really
I'm creating a package that is going to be used by R (the statistical

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.