我正在尝试在我的本地主机上测试 Google App Engine Java 后端。我正在运行后端,并且编写了一个 servlet。
但是,当我在后端向 url 发帖时:
http://localhost:8888/MyServlet/
我得到的是:
WARNING: No file found for: /MyServlet/
我如何实际调用后端为我启动一个实例,以便我可以在本地对其进行测试并发布帖子?
小服务程序:
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");
}
网页.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>