【问题标题】:Error while using JSP with App Engine将 JSP 与 App Engine 结合使用时出错
【发布时间】:2013-12-23 10:42:11
【问题描述】:

这是我的 JSP 文件。该文件的名称是 NewFile.jsp。

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello this is JSP Page
</body>
</html>

这是小服务程序。

    package pack.exp;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class JspTestingServlet extends HttpServlet 
{
     private static String Test_JSP = "/NewFile.jsp";

    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException 
    {
        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, world");

        String forward="";
        forward= Test_JSP;

        RequestDispatcher view = req.getRequestDispatcher(forward);


        try 
        {
            view.forward(req, resp);
        }

        catch (ServletException e) 
        {
            e.printStackTrace();
        }
    }
}

这是我的 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>JspTesting</servlet-name>
        <servlet-class>pack.exp.JspTestingServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>JspTesting</servlet-name>
        <url-pattern>/jsptesting</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

部署应用程序后,我收到 HTTP 404 page not found 错误 我是jsp新手,请有人帮助我。

【问题讨论】:

  • 告诉你如何使用 URL 来访问 JSP 和 servlet 映射的 web.xml 条目。
  • 你已经将它转发到 NewFile.jsp,但是你有 MyFile.jsp
  • 抱歉打错了,我已经更新了。
  • 桑托什,我已经更新了 web.xml 文件。
  • @user2558087 你有 index.html 吗,如果它有什么,什么时候你得到 404 错误

标签: java google-app-engine jsp servlets


【解决方案1】:

您的代码很好。如您所示,问题出在您的 web.xml 中。

您在 web.xml 中的 servlet 类定义是

<servlet-class>pack.exp.JspAppEngineServlet</servlet-class>

您的 Servlet java 文件名为:Jsp_App_EngineServlet。存在不匹配,因此未找到。

所以,将 Java 文件名更改为:JspAppEngineServlet 应该没问题。

【讨论】:

  • 对我来说一切都很好。我已经在本地设置了您的文件,当您单击可用的 Servlet 时,页面会正常显示。该应用程序是否在本地运行?点击Available Servlet时能不能上传错误页面?
  • 这是新项目,代码相同..我部署在应用引擎上 你可以点击这个链接查看错误1.shanxdemo.appspot.com
  • 您在上面部署的应用程序中的 JSPTesting 链接是指 /jsptesting。这未在您的 web.xml 中定义。在您的 web.xml 中,您放置了 /jspappengine。所以纠正它,它会没事的。
  • 实际上我创建了一个名为“Jsp Testing”的新项目,所以在我的 web.xml /jsptesting 中写了这很好。我现在将更新问题。
  • 好吧,如果您在此处保留不一致的代码以及在服务器上保留其他内容,我无法提供帮助。除了拼写错误、缺少声明等,我没有发现任何特别错误的地方。另一点是您的项目中有 JSP。您是否使用了正确的 JDK,确保在上传到 GAE 时没有收到错误等等。最后,您的项目是否在本地工作?
猜你喜欢
  • 2013-12-23
  • 1970-01-01
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 2020-04-29
  • 2020-05-26
  • 2014-03-29
相关资源
最近更新 更多