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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:19:02+00:00 2026-06-09T09:19:02+00:00

I got tomcat running on port 8080 and simple servlet: import java.io.*; import java.text.*;

  • 0

I got tomcat running on port 8080 and simple servlet:

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.*;

public class MyHelloWorld extends HttpServlet {

    public void doGet(HttpServletRequest request, 
            HttpServletResponse response)
    throws IOException, ServletException
    {
        String data = "Hello World from servlet!";
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(data);
    }
}

wget on URL to this servelet, retrives a string:

"Hello World from servlet!"

also web browser prints it, so it works, and tomcat’s access log shows response ‘200’

But when im trying to get this string via my javascript:

<html>

<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>


            $.getJSON({ 
    type: "GET", url: "http://localhost:8080/examples/MyHelloWorld", 
    contentType: "text/plain", 
    error: function(xhr, ajaxOptions, thrownError){ 
                alert(ajaxOptions);
                alert(xhr.status); 
                alert(thrownError);
            }, 
    processData: true, 
    success: function(data, textStatus, jqXHR){ alert(data); }
});
</script>

</script>

</head>

In tomcat’s log i can see response 200, but browser does not show anything – just blank page with no content. If I change getJSON into get or ajax i get alerts with:

xhr.status = 0
ajaxOptions = "error"
thrownError = empty

web server is apache and it runs on port 80

Thx for all help

  • 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-09T09:19:03+00:00Added an answer on June 9, 2026 at 9:19 am

    Try something like this:

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String data = "Hello World from servlet!";
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
    
        if (request.getContentType().equals("application/json")) {
            data = "\"" + data + "\"";
        }
    
        response.getWriter().write(data);
    }
    

    And in your js:

    $.getJSON("http://localhost:8080/examples/MyHelloWorld", function(data) {
       alert(data)
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've got a (probably very simple) problem with jquery. I'm running a Java Servlet
I've got Hudson (continuous integration system) with the git plugin running on a Tomcat
I've got a Java web app (WAR) deployed to Tomcat on a remote Solaris
I've got a Red Hat box with 6G memory running Tomcat and I'm trying
I've got a struts2 application running under a contextpath /path on my local tomcat
I'm trying out Endeavour Software Project Management.It's running as a servlet in Tomcat (Catalina).
I'm running Tomcat 6 on Windows. I've got the Monitor Tomcat system tray icon
i got a struts web application (running on tomcat 6) with all files except
Okay, so I've been running a Java/Jersey webservice on Tomcat with basic authentication which
Got two applications running on tomcat: Application1 (JSP) Application2 (Webservices) I want to set

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.