Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Servlet不指向JSP页面_Java_Html_Jsp_Servlets_Jdbc - Fatal编程技术网

Java Servlet不指向JSP页面

Java Servlet不指向JSP页面,java,html,jsp,servlets,jdbc,Java,Html,Jsp,Servlets,Jdbc,我们需要使用Java、HTML、bean和JSP编写Web应用程序。问题是我从未参加过HTML或CSS课程 我有一个名为index.HTML的基本HTML页面,它在带有提交按钮的文本字段中获取用户的名字和姓氏。当我按下submit时,我得到一个“页面无法显示错误”。我已经将我的代码与我的导师进行了比较,结果非常相似,因此我不确定我做错了什么。任何帮助都将不胜感激 另外,不要介意我糟糕的格式 index.html <!DOCTYPE html> <html> <

我们需要使用Java、HTML、bean和JSP编写Web应用程序。问题是我从未参加过HTML或CSS课程

我有一个名为index.HTML的基本HTML页面,它在带有提交按钮的文本字段中获取用户的名字和姓氏。当我按下submit时,我得到一个“页面无法显示错误”。我已经将我的代码与我的导师进行了比较,结果非常相似,因此我不确定我做错了什么。任何帮助都将不胜感激

另外,不要介意我糟糕的格式

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Final Project</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <h1>Welcome to Banking by Tyler Weaver</h1>
        <h4>Please Enter your First and Last Name</h4>
        <form action="BankingControl" method="POST">
            <input type="hidden" name="action" value="Menu">   
            First Name:
            <input type="text" name="FirstName" required/> <br></>
            Last Name:
            <input type="text" name="LastName" required/> <br></>
            <input type="submit" value="Login"/>  
        </form>
    </body>
</html>
java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import utilities.ErrorLogger;

public class MySQL {

    private final String databaseURL;
    private final String userName;
    private final String password;

    public MySQL(String databaseURL, String userName, String password) {
        this.databaseURL = databaseURL;
        this.userName = userName;
        this.password = password;
        initDB();
    }

    private void initDB() {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance(); //Not needed for MySQL - here for show only
        } catch (ClassNotFoundException ex) {
            ErrorLogger.log(Level.SEVERE, "Could not find the class com.mysql.jdbc.Driver \n"
                    + "Program will now exit. ", ex);
            System.exit(1);
        } catch (InstantiationException ex) {
            ErrorLogger.log(Level.SEVERE, "Could not instaniate the class com.mysql.jdbc.Driver \n"
                    + "Program will now exit. ", ex);
            System.exit(1);
        } catch (IllegalAccessException ex) {
            ErrorLogger.log(Level.SEVERE, "Could not access the class com.mysql.jdbc.Driver \n"
                    + "Program will now exit. ", ex);
            System.exit(1);
        }
        try {
            Connection conn = DriverManager.getConnection(databaseURL, userName, password);
            conn.close();
        } catch (SQLException ex) {
            ErrorLogger.log(Level.SEVERE, "Could not connect to the database. "
                    + "Database string = "
                    + databaseURL + " user =  " + userName + " password " + password, ex);
            System.exit(1);
        }
    }

    public Connection getConnection() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(databaseURL, userName, password);
        } catch (SQLException e) {
            ErrorLogger.log(Level.SEVERE, "Could not connect to the database. "
                    + "Database string = "
                    + databaseURL + " user =  " + userName + " password " + password);
            System.exit(1);
        }
        return conn;
    }

    public void closeConnection(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                ErrorLogger.log(Level.SEVERE, "SQL Exception is thrown while "
                        + "trying to close a Connection object. The connection "
                        + "object was not null.", e);
            }
        }
    }

}
ErrorLogger.java

import java.io.IOException;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ErrorLogger {

    private static final String errorFileName = "SQLErrorLogger";
    public static boolean showLogInErrorWindow = true;

    private static Logger errorLogger;

    private static void initializeLogging() throws IOException {
        String logFile = getLogfileName();
        errorLogger = Logger.getLogger(logFile);
        Handler handler = new FileHandler(logFile);
        handler.setFormatter(new java.util.logging.SimpleFormatter());
        if (showLogInErrorWindow) {
            errorLogger.setUseParentHandlers(true);
        } else {
            errorLogger.setUseParentHandlers(false);
        }
        errorLogger.addHandler(handler);
    }

    private static String getFormattedDate(Date date) {
        DateFormat format;
        format = new SimpleDateFormat("MM-dd-yyyy");

        return (format.format(date));
    }

    private static String getFormattedTime(Date date) {
        DateFormat format;
        format = new SimpleDateFormat("hh.mm.a");

        return (format.format(date));
    }

    private static String getDateTime(Date date) {
        String sDateTime = getFormattedDate(date) + "_"
                + getFormattedTime(date);
        return sDateTime;
    }

    private static String getLogfileName() {
        String logFileName = errorFileName;

        Date date = new Date(System.currentTimeMillis());
        String sFormattedDateTime = getDateTime(date);
        logFileName += "_" + sFormattedDateTime;
        logFileName += ".log";

        return logFileName;
    }

    public static String getNewLogFileName(String logFileBase, String logFileExt) {
        String logFile = logFileBase;
        Date date = new Date(System.currentTimeMillis());
        String sFormattedDateTime = getDateTime(date);
        logFile += "_" + sFormattedDateTime;
        logFile += logFileExt;
        return logFile;
    }

    public static void log(Level level, String message, Throwable ex) {
        if (errorLogger == null) {
            initLogger();
        }
        errorLogger.log(level, message, ex);
    }

    public static void log(Level level, String message) {
        if (errorLogger == null) {
            initLogger();
        }
        errorLogger.log(level, message);
    }

    private static void initLogger() {
        try {
            initializeLogging();
        } catch (IOException ex) {
            errorLogger = Logger.getLogger(getLogfileName());//Will not write to a file
            errorLogger.log(Level.SEVERE, "Could not create a file handler for teh error logger");
        }
    }

    public static void main(String[] args) {
        ErrorLogger.log(Level.SEVERE, "Test error Message");
    }

}
除了样本数据库和信息之外,这应该是重现错误的最低要求。所有JSP页面单独加载,但不会从index.html开始。这使得调试应用程序的其余部分变得困难。任何帮助都将不胜感激

目录:


错误的图像


在这里输入一个答案,以防有人遇到这个问题。问题是由于缺少JAR而发生的内部服务器错误

您应该提供完整的web.xml以及错误的含义(签入控制台-服务器返回错误或浏览器根本不想连接)。伙计们,请表现出最小的努力!我想看看目录结构和你可能有的其他控制器。您正在重定向到一个资源,但我不知道该资源是否与root位于同一目录中,还是位于其他地方?干杯。@MichalWilkowski如何显示web.xml?我会在上面列出我的目录结构!顺便说一句,当从index.html转到jsp时,您的url是否如您所期望的那样?我觉得你的转发是相对的,而不是绝对的,所以它实际上发送到了一个错误的url。我从index.html转到bankingcontrolservlet,它将把它指向一个jsp。我使用相同的结构,将URL完全按照我的导师所说的方式记录下来。
import java.io.IOException;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ErrorLogger {

    private static final String errorFileName = "SQLErrorLogger";
    public static boolean showLogInErrorWindow = true;

    private static Logger errorLogger;

    private static void initializeLogging() throws IOException {
        String logFile = getLogfileName();
        errorLogger = Logger.getLogger(logFile);
        Handler handler = new FileHandler(logFile);
        handler.setFormatter(new java.util.logging.SimpleFormatter());
        if (showLogInErrorWindow) {
            errorLogger.setUseParentHandlers(true);
        } else {
            errorLogger.setUseParentHandlers(false);
        }
        errorLogger.addHandler(handler);
    }

    private static String getFormattedDate(Date date) {
        DateFormat format;
        format = new SimpleDateFormat("MM-dd-yyyy");

        return (format.format(date));
    }

    private static String getFormattedTime(Date date) {
        DateFormat format;
        format = new SimpleDateFormat("hh.mm.a");

        return (format.format(date));
    }

    private static String getDateTime(Date date) {
        String sDateTime = getFormattedDate(date) + "_"
                + getFormattedTime(date);
        return sDateTime;
    }

    private static String getLogfileName() {
        String logFileName = errorFileName;

        Date date = new Date(System.currentTimeMillis());
        String sFormattedDateTime = getDateTime(date);
        logFileName += "_" + sFormattedDateTime;
        logFileName += ".log";

        return logFileName;
    }

    public static String getNewLogFileName(String logFileBase, String logFileExt) {
        String logFile = logFileBase;
        Date date = new Date(System.currentTimeMillis());
        String sFormattedDateTime = getDateTime(date);
        logFile += "_" + sFormattedDateTime;
        logFile += logFileExt;
        return logFile;
    }

    public static void log(Level level, String message, Throwable ex) {
        if (errorLogger == null) {
            initLogger();
        }
        errorLogger.log(level, message, ex);
    }

    public static void log(Level level, String message) {
        if (errorLogger == null) {
            initLogger();
        }
        errorLogger.log(level, message);
    }

    private static void initLogger() {
        try {
            initializeLogging();
        } catch (IOException ex) {
            errorLogger = Logger.getLogger(getLogfileName());//Will not write to a file
            errorLogger.log(Level.SEVERE, "Could not create a file handler for teh error logger");
        }
    }

    public static void main(String[] args) {
        ErrorLogger.log(Level.SEVERE, "Test error Message");
    }

}