diff --git a/src/main/java/servlet/Database.java b/src/main/java/servlet/Database.java index 360009d..1a3c4a5 100644 --- a/src/main/java/servlet/Database.java +++ b/src/main/java/servlet/Database.java @@ -6,14 +6,6 @@ import java.sql.*; * Class for managing the database. */ public class Database implements AutoCloseable { - - // If you have the mysql server on your own computer use "localhost" as server - // address. - private static String databaseServerAddress = "vm26.cs.lth.se"; - private static String databaseUser = ""; // database login user - private static String databasePassword = ""; // database login password - private static String database = ""; // the database to use, i.e. - // default schema private Connection conn = null; public Database() { diff --git a/src/main/java/servlet/Dump.java b/src/main/java/servlet/Dump.java deleted file mode 100644 index 973031a..0000000 --- a/src/main/java/servlet/Dump.java +++ /dev/null @@ -1,120 +0,0 @@ -package servlet; - -import java.io.*; -import java.sql.SQLException; - -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet implementation class Survey. - */ -@WebServlet("/Dump") -public class Dump extends HttpServlet { - private static final long serialVersionUID = 1L; - - // Define states - private static final int NEED_NAME = 0; - private static final int NEED_PROJECT_DATA = 2; - - private FormGenerator formGenerator = new FormGenerator(); - - /** - * Default constructor. - */ - public Dump() { - } - - /* - * Checks first if name includes characters (i.e. is longer than zero - * characters) and then - * if so if the name is possible to add to - * the database. It is not possible to add an already existing name to the - * database. - */ - boolean nameOk(Database db, String name) { - boolean result = !name.equals(""); - if (result) - result = db.addName(name); - return result; - } - - boolean answerOk(Database db, String answerOne, String answerTwo, String answerThree, String answerFour) { - boolean result = !answerOne.equals("") && !answerTwo.equals("") && !answerThree.equals("") - && !answerFour.equals(""); - if (result) - result = db.addAnswer(answerFour, answerOne, answerTwo, answerThree, answerFour); - return result; - } - - /* - * Checks if a value entered as answer is OK. Answers should be between 1 and - * 10. - */ - boolean valueOk(int value) { - return value > 0 && value < 11; - } - - protected boolean updateAnswers(String answerOne, String answerTwo) { - return true; - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - // Try with resources to create a connection, will ensure close is always - // called. - try (Database db = new Database()) { - - // Get the session - HttpSession session = request.getSession(true); - - int state = 0; - String name; - boolean sessionShouldBeEnded = false; - - // Decide which state the session is in - if (session.isNew()) - state = NEED_NAME; - else { - state = (Integer) session.getAttribute("state"); - } - - // Get a writer, which will be used to write the next page for the user - PrintWriter out = response.getWriter(); - - // Start the page, print the HTML header and start the body part of the page - out.println(""); - out.println(" FANTASTIC WEB APPLICATION "); - out.println(""); - - // Save the state in the session until next time doGet is requested - session.setAttribute("state", state); - - // Print the end of the HTML-page - out.println(""); - - if (sessionShouldBeEnded) - session.invalidate(); - } catch (SQLException ex) { - // If Database.close for any reason fails. - throw new ServletException(ex); - } - } - - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse - * response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doGet(request, response); - } -} diff --git a/src/main/java/servlet/Survey.java b/src/main/java/servlet/Survey.java index 3a564e2..4e46a7b 100644 --- a/src/main/java/servlet/Survey.java +++ b/src/main/java/servlet/Survey.java @@ -130,8 +130,6 @@ public class Survey extends HttpServlet { s12 = Integer.parseInt(s12String); s13 = Integer.parseInt(s13String); s14 = Integer.parseInt(s14String); - - String str = s11String + s12String + s13String; } catch (NumberFormatException e) { valuesOk = false; }