我用 JSP 创建了我的第一个 Java Servlet 应用程序来创建关于书籍的记录并显示它们。index.html 页面加载良好,但项目中的其他页面在部署到 GoogleAppEngine 时无法正常工作。通过 eclipse 在 App Engine 上本地运行时,相同的项目运行良好。我还在“appengine-web.xml”中启用了会话,但问题仍然存在。该应用程序在本地运行时运行良好。通过应用程序引擎运行我得到错误 -Error: Not Found
The requested URL /BookApp was not found on this server.目录结构索引.html<!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Create a book entry</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script></head><body><div class="container"> <h2>Create A Book</h2> <form action="BookApp" method="post"> <div class="form-group"> <label for="Title">Title:</label> <input type="text" class="form-control" id="tbBook" placeholder="Enter Title" name="bookname" required> </div> <div class="form-group"> <label for="author">Author:</label> <input type="text" class="form-control" id="authorname" placeholder="Enter Author" name="authorname" required> </div> <div class="form-group"> <label for="cost">Cost:</label> <input type="text" class="form-control" id="tbCost" placeholder="Enter Cost" name="cost" required> </div> <button type="submit" class="btn btn-default">Create</button> </form></div></body></html>
1 回答
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
当您使用 Java8 ( <runtime>java8</runtime>) 并按照 Google App 引擎规范尝试实现这种方式时:
// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.
@WebServlet(name = "requests", description = "Requests: Trivial request", urlPatterns = "/requests")
public class RequestsServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
添加回答
举报
0/150
提交
取消