Cleaning and deleting unused files
This commit is contained in:
parent
66ff5c2efd
commit
0043e3d9c0
3 changed files with 0 additions and 130 deletions
|
@ -6,14 +6,6 @@ import java.sql.*;
|
||||||
* Class for managing the database.
|
* Class for managing the database.
|
||||||
*/
|
*/
|
||||||
public class Database implements AutoCloseable {
|
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 = "<your databse user on vm26>"; // database login user
|
|
||||||
private static String databasePassword = "<your password>"; // database login password
|
|
||||||
private static String database = "<your database, normally the same as database user>"; // the database to use, i.e.
|
|
||||||
// default schema
|
|
||||||
private Connection conn = null;
|
private Connection conn = null;
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
|
|
|
@ -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("<html>");
|
|
||||||
out.println("<head><title> FANTASTIC WEB APPLICATION </title></head>");
|
|
||||||
out.println("<body>");
|
|
||||||
|
|
||||||
// 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("</body></html>");
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -130,8 +130,6 @@ public class Survey extends HttpServlet {
|
||||||
s12 = Integer.parseInt(s12String);
|
s12 = Integer.parseInt(s12String);
|
||||||
s13 = Integer.parseInt(s13String);
|
s13 = Integer.parseInt(s13String);
|
||||||
s14 = Integer.parseInt(s14String);
|
s14 = Integer.parseInt(s14String);
|
||||||
|
|
||||||
String str = s11String + s12String + s13String;
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
valuesOk = false;
|
valuesOk = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue