0

I am trying to build a simple Google visualization web app using a java servlet. I finally got all the code working and imported correctly, however, for some reason I am getting a 404 on the query page. My web.xml file looks like it is setup correctly...

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>My Servlet</servlet-name>
        <servlet-class>Servlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>My Servlet</servlet-name>
        <url-pattern>/simpleexample</url-pattern>
    </servlet-mapping>
</web-app>

However, whenever my app makes a request to /simpleexample I get a 404 error enter image description here

The URL is correct when looking for that page...

http://localhost:8080/simpleexample?tq=select%20name,population&tqx=reqId%3A0

To call that I am using google.visualization.Query...

var query = new google.visualization.Query("/simpleexample?tq=select name,population");
query.send(handleSimpleResponse);

can anyone see why that would be giving me a 404? I am very confused right now. Thank you.

Here is my Servler.java file. It extends a class from The Google Visualization Java library which automatically handles the doGet and doPost requests, it forwards them on to the generateDataTable method...

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

import com.google.visualization.datasource.DataSourceServlet;
import com.google.visualization.datasource.base.TypeMismatchException;
import com.google.visualization.datasource.datatable.ColumnDescription;
import com.google.visualization.datasource.datatable.DataTable;
import com.google.visualization.datasource.datatable.value.ValueType;
import com.google.visualization.datasource.query.Query;


public class Servlet extends DataSourceServlet {




    @Override
    public DataTable generateDataTable(Query q, HttpServletRequest request) {
        DataTable d = new DataTable();
        ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
        cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal Name"));
        cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to Wikipedia"));
        cd.add(new ColumnDescription("population", ValueType.NUMBER, "Population Size"));
        cd.add(new ColumnDescription("Vegetarian", ValueType.BOOLEAN, "Vegetarian?"));

        d.addColumns(cd);

        try {
            d.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/Aye-aye", 100, true);
            d.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/Sloth", 300, true);
            d.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/Leopard", 50, false);
            d.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/Tiger", 80, false);
        } catch (TypeMismatchException e) {
            System.out.println("Invalid type!");
        }
        return d;
    }

    @Override
    protected boolean isRestrictedAccessMode() { return false; }
}

If needed the example this is from is found here.. https://github.com/google/google-visualization-java

7
  • 1
    The servlet-class tag should be point to your Servlet class and look something like <servlet-class>com.test.SimpleExampleServlet</servlet-class>. You also need to have a SimpleExampleServlet class that extends HttpServlet.
    – Joey Chong
    Commented Feb 1, 2019 at 1:34
  • The class "Servlet" does extend the HttpServlet. I thought that setting the url pattern to /simpleexample and setting the servlet-name would tell the application that when you go to /simpleexample it would use the "My Servlet" which is mapped to class Servlet? Commented Feb 1, 2019 at 18:46
  • Can you update your question to show your Servlet code?
    – skomisa
    Commented Feb 2, 2019 at 1:54
  • @skomisa I updated my question to include the servlet.java code Commented Feb 5, 2019 at 1:12
  • Sorry for late reply as I am on Holiday. May I know what is your web app context? You deploy the web app under ROOT?
    – Joey Chong
    Commented Feb 12, 2019 at 1:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.