簡體   English   中英

將JSP與App Engine一起使用時出錯

[英]Error while using JSP with App Engine

這是我的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>

這是servlet。

    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頁面的錯誤我是jsp的新手,請有人幫助我。

您的代碼很好。 如圖所示,問題出在web.xml中。

您在web.xml中的servlet類定義是

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

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

因此,將Java文件名更改為: JspAppEngineServlet ,應該沒問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM