0
votes

I am trying to test a Google App Engine Java Backend on my localhost. I have the backend running, and I have a servlet written.

However, when I do a post to my backend to url:

http://localhost:8888/MyServlet/

All I get is this:

WARNING: No file found for: /MyServlet/

How do I actually call the backend to start a an instance for me so I can test it locally and do a post?

Servlet:

    import java.io.BufferedReader;
    import java.io.IOException;
    import javax.servlet.http.*;

    import com.google.gson.Gson;
    import com.google.gson.GsonBuilder;

    @SuppressWarnings("serial")
    public class MyServlet extends HttpServlet {
        public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

    resp.setContentType("text/plain");
    resp.getWriter().println("Hello, world");
}

web.xml:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <servlet>
        <servlet-name>MyBackend</servlet-name>
        <servlet-class>com.test.backend.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/_ah/start</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>
3

3 Answers

1
votes

try to use both a servlet and servlet-mapping tags like this:

<servlet>
    <servlet-name>MyBackend</servlet-name>
    <servlet-class>com.test.backend.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MyBackend</servlet-name>
    <url-pattern>/MyServlet</url-pattern>
</servlet-mapping>

though i feel like suggesting not using words like servlet or backend in class names; they are meaningless outside the context of a developer and do not give a clue about the functionality of the class

0
votes

i also just realized that you implemented doPost, which is meant to handle form submissions, it will not handle a naked url request in the browser like that, change your method to doGet or service http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServlet.html

0
votes

My problem was that I did not start my backend. You first have to write a servlet that listens for /_ah/start and responds to it before your backends will start up.

Here is another question of mine that got it solved