【问题标题】:Getting Blank page While using JSP with Google App Engine将 JSP 与 Google App Engine 结合使用时出现空白页
【发布时间】:2013-12-23 10:57:59
【问题描述】:
 package com.example.datastoreWrite;

 import java.io.IOException;

 import javax.servlet.ServletException;

 import javax.servlet.http.HttpServlet;

 import javax.servlet.http.HttpServletRequest;

 import javax.servlet.http.HttpServletResponse;

 @SuppressWarnings("serial")

 public class DataStoreWriteServlet extends HttpServlet
 {

 @Override

 protected void doGet(HttpServletRequest req, HttpServletResponse resp)

 throws ServletException, IOException {

 // TODO Auto-generated method stub

 Key v1 = KeyFactory.createKey("Person", "Raghav");

 Key r1 = KeyFactory.createKey("Person", "vinay");

 DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

 Entity e1, e2;

 try {

 e1 = datastore.get(r1);

 e2 = datastore.get(v1);

 Long vAge = (Long) e1.getProperty("age");

 Long rAge = (Long) e2.getProperty("age");

 System.out.println("vinay age"+vAge);

 System.out.println(" age"+rAge);

 } catch (EntityNotFoundException e) {

 // Alice or Bob doesn't exist!
 }
 String message = "Simple";

 req.setAttribute("message", message); // This will be available as ${message}

 try {

 req.getRequestDispatcher("/Show.jsp").forward(req, resp);

 } catch (ServletException e) {

 // TODO Auto-generated catch block

 e.printStackTrace();
 }}}

这是我的 JSP 文件

 <%@ page language="java"

 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

 <title>Simple DataStore Display</title></head>

 <body><p>Message: ${message}</p></body>

 </html>

我的 WEB.xml

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>SimpleDataStoreApplicationTest</servlet-name>
<servlet-class>com.datasote.test.SimpleDataStoreApplicationTestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleDataStoreApplicationTest</servlet-name>
<url-pattern>/simpledatastoreapplicationtest</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list></web-app>

【问题讨论】:

    标签: java google-app-engine


    【解决方案1】:

    我怀疑您忘记在 Show.jsp 文件中正确关闭页面指令。

    请使用:&lt;%@ page language="java"%&gt;

    除上述之外,您的代码看起来很好执行,如果数据不存在,您将在Show.jsp 页面中看到Message: Simple 输出。

    【讨论】:

    • 我已经正确写了标签,这是stackoverflow模板中的格式问题。
    • 好的。请显示 web.xml 文件以及您如何调用 Servlet。
    • 亲爱的 Romie 我已经添加了我正在使用的 web.xml 文件。
    • 我不确定您是否在此处输入代码并无意中引入了拼写错误,但您在 web.xml 中放入的包+类名是 com.example.datastore.DataStoreExampleServlet,而它应该是com.example.datastoreWrite.DataStoreWriteServlet 根据您的 .Java 文件。请检查。
    • 实际上我已经创建了两个 servlet 类,一个是写入 appengine 数据存储,第二个是从中获取。所以我上面写的类是 DataStoreWriteServlet 和 web.xml 文件是 DataStoreExampleServlet 。抱歉有拼写错误应该是 com.example.datastore.DataStoreExampleServlet 。但我又遇到了同样的错误
    猜你喜欢
    • 2013-12-23
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2020-05-26
    • 2014-08-26
    • 2014-03-29
    相关资源
    最近更新 更多