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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:00:27+00:00 2026-06-09T00:00:27+00:00

My Folder Structure: Servlet: @WebServlet(name = KPItoGSON, urlPatterns = {/KPItoGSON/*}) public class KPItoGSON extends

  • 0

My Folder Structure:

enter image description here

Servlet:

@WebServlet(name = "KPItoGSON", urlPatterns = {"/KPItoGSON/*"})

    public class KPItoGSON extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet KPItoGSON</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet KPItoGSON at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
        Gson gson = new Gson();
        HttpServletRequest req = (HttpServletRequest) request;
        KPIListController klc = (KPIListController) req.getSession().getAttribute("kpilist");
        String json = gson.toJson(klc);
        Logger.getLogger(KPItoGSON.class.getName()).warning("The value is"+klc.getKPI().get(1).getUSTER());
        Logger.getLogger(KPItoGSON.class.getName()).info("The json "+json);


      response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write(json);
}

JQuery:

function onButtonClickOrCertainTime(){
     $.get('KPItoGSON', function(responseText) { // 
            alert(responseText);        
        });
}

Error:

/GISPages/KPI/KPItoGSON 404 (Not Found) 

I am trying this example by BalusC.With this example I want to get new data from database into javascript variable and do some charting. I am not used to servlet :(. What is the problem with sending request to servlet using jQuery? Since I want new data each time button or poll using function onButtonClickOrCertainTime from database is using GSON and Servlet way is better or is it possible with jstl?

  • 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-09T00:00:30+00:00Added an answer on June 9, 2026 at 12:00 am

    Your servlet is mapped on /KPItoGSON/* and your webapp seems based on the information provided so far to be deployed on the context root. Your servlet is thus listening on http://localhost:8080/KPItoGSON.

    Your 404 error indicates that the servlet is been invoked from a HTML page in the /GISPages/KPI folder. You’ve specified a path-relative servlet URL in $.get() so it’s relative to the top folder in the current request URL (the URL as you see in browser’s address bar). It is trying to invoke the servlet by URL http://localhost:8080/GISPages/KPI/KPItoGSON which is thus invalid. It should have invoked the servlet by URL http://localhost:8080/KPItoGSON.

    Apart from moving the HTML page two folders up, you can fix it by going two folders up in the ajax request URL:

    $.get('../../KPItoGSON', function(responseText) {
        alert(responseText);        
    });
    

    or by using a domain-relative URL (starting with a leading slash):

    $.get('/KPItoGSON', function(responseText) {
        alert(responseText);        
    });
    

    By the way, you should remove the processRequest() method from your servlet. Your JSON output is now malformed with a piece of irrelevant HTML.

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

Sidebar

Related Questions

Suppose somewhere I import javax.servlet.http.HttpServlet . My questions: Does this mean: I could find
I have got following folder structure for my domain (domain.com): /data/images (it´s subdomain name,
I have a folder structure like this /img/products/{product name}/ and then the sub folders
In the MVC folder structure, where should general class files reside? For example, I
the folder structure is like this: plugin->upload->php->files list-> 'script_url' => $this->getFullUrl().'/'.basename(__FILE__), //'upload_dir' => dirname(__FILE__).'/files/',
My folder structure is like - root admin create_page.php pages my_page1.php my_page2.php I have
I have the following folder structure /project /scrape item.py /spiders myscraper.py inside the file
I have a folder structure as follows: mydomain.example ->Folder-A ->Folder-B I have a string
I have folder structure and I would like to create JSON objects based on
I have a folder structure like this: /some_folder /tmp /tmp/foo /tmp/foo/fu * /tmp/bar /tmp/bar/bah

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.