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
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
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 extendsHttpServlet
.