java - Servlet not directing to JSP page -


we required write web application using java, html, beans, , jsps. problem have never taken html or css course.

i have base html page called index.html takes user's first , last name in text field submit button. when press submit "page cannot displayed error." have compared code instructors , similar unsure doing wrong. appreciated.

also, not mind horrible formatting.

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 banking tyler weaver</h1>         <h4>please enter first , 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> 

bankingcontrol.java

import beans.user; import database.mysql; import java.io.ioexception; import java.sql.connection; import java.sql.sqlexception; import java.util.logging.level; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import utilities.errorlogger;  @webservlet(name = "bankingcontrol", urlpatterns = {"/bankingcontrol"}) public class bankingcontrol extends httpservlet {      private static final string mysqlprefix = "jdbc:mysql://";     private static final string hostname = "cs3db.bloomu.edu";     private static final string databasename = "cs3";     private static final string databaseurl = mysqlprefix + hostname + "/" + databasename;     private static final string username = "tgw46366";     private static final string password = "tgw46366";      protected void processrequest(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         response.setcontenttype("text/html;charset=utf-8");          //creates mysql database connection specified information         mysql mysql = new mysql(databaseurl, username, password);          //the url processor send.         string jsp_url = "/index.html";          //tries making connection database         try (connection conn = mysql.getconnection()) {             errorlogger.log(level.info, "database connection obtained");              //retrieve action page             string action = request.getparameter("action").trim();             //if action null, make menu             if (action == null) {                 action = "menu";             }              user user = new user();             user.setfirstname(request.getparameter("firstname").trim());             user.setlastname(request.getparameter("lastname").trim());             request.setattribute("user", user);              //check see if action menu             if (action.equalsignorecase("menu")) {                 //place send information                 jsp_url = "/menu.jsp";                  errorlogger.log(level.info, "user " + user.getfirstname() + " "                         + user.getlastname()                         + " logged in - menu page returned");             } else if (action.equalsignorecase("newcustomer")) {                 jsp_url = "/newcustomer.jsp";                  errorlogger.log(level.info, "new customer selected");             } else if (action.equalsignorecase("newaccount")) {                 jsp_url = "/newaccount.jsp";                  errorlogger.log(level.info, "new account selected");             } else if (action.equalsignorecase("accounttransaction")) {                 jsp_url = "/transaction.jsp";                  errorlogger.log(level.info, "account transaction selected");             } else if (action.equalsignorecase("logout")) {                 jsp_url = "/index.html";                  errorlogger.log(level.info, "logout selected");             } else {                 errorlogger.log(level.warning,                         "invalid option -- index.html returned");             }              //if connection cannot made, throw here         } catch (sqlexception ex) {             errorlogger.log(level.severe,                     "not making database connection @ time", ex);         }          //forward correct jsp         getservletcontext()                 .getrequestdispatcher(jsp_url)                 .forward(request, response);     }      @override     protected void doget(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         processrequest(request, response);     }      @override     protected void dopost(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {         processrequest(request, response);     }      @override     public string getservletinfo() {         return "short description";     }  } 

mysql.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 mysql - here show         } catch (classnotfoundexception ex) {             errorlogger.log(level.severe, "could not find class com.mysql.jdbc.driver \n"                     + "program exit. ", ex);             system.exit(1);         } catch (instantiationexception ex) {             errorlogger.log(level.severe, "could not instaniate class com.mysql.jdbc.driver \n"                     + "program exit. ", ex);             system.exit(1);         } catch (illegalaccessexception ex) {             errorlogger.log(level.severe, "could not access class com.mysql.jdbc.driver \n"                     + "program 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 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 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 thrown while "                         + "trying close connection object. connection "                         + "object 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 file             errorlogger.log(level.severe, "could not create file handler teh error logger");         }     }      public static void main(string[] args) {         errorlogger.log(level.severe, "test error message");     }  } 

this should minimum required reproduce wrong aside sample database , information. of jsp pages load individually not start index.html. makes difficult debug rest of application. appreciated.

directory:director img


image of errors!first image

errorimage

just put answer here in case running this. problem internal server error occurred due missing jars.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -