From d26dbab8f789d787d5c39f8700b4ac19701f286f Mon Sep 17 00:00:00 2001 From: Julien Sere Date: Sat, 22 Jan 2011 17:22:13 +0000 Subject: initial check out java git-svn-id: file:///var/svn/2011-usi/trunk@13 db941bf7-0cb3-4dda-9634-87faf64f93a7 --- app/v2_java/.classpath | 21 + app/v2_java/.pmd | 941 +++++++++++++++++++++ app/v2_java/.project | 36 + app/v2_java/.settings/.jsdtscope | 11 + app/v2_java/.settings/org.eclipse.jdt.core.prefs | 7 + .../.settings/org.eclipse.wst.common.component | 9 + .../org.eclipse.wst.common.project.facet.core.xml | 7 + .../org.eclipse.wst.jsdt.ui.superType.container | 1 + .../org.eclipse.wst.jsdt.ui.superType.name | 1 + app/v2_java/WebContent/META-INF/MANIFEST.MF | 3 + app/v2_java/WebContent/WEB-INF/web.xml | 31 + app/v2_java/WebContent/game.html | 22 + app/v2_java/WebContent/index.html | 10 + app/v2_java/WebContent/login.html | 20 + app/v2_java/WebContent/user.html | 28 + app/v2_java/src/org/usi2011/Database.java | 73 ++ app/v2_java/src/org/usi2011/Question.java | 67 ++ app/v2_java/src/org/usi2011/User.java | 56 ++ 18 files changed, 1344 insertions(+) create mode 100644 app/v2_java/.classpath create mode 100644 app/v2_java/.pmd create mode 100644 app/v2_java/.project create mode 100644 app/v2_java/.settings/.jsdtscope create mode 100644 app/v2_java/.settings/org.eclipse.jdt.core.prefs create mode 100644 app/v2_java/.settings/org.eclipse.wst.common.component create mode 100644 app/v2_java/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100644 app/v2_java/WebContent/META-INF/MANIFEST.MF create mode 100644 app/v2_java/WebContent/WEB-INF/web.xml create mode 100644 app/v2_java/WebContent/game.html create mode 100644 app/v2_java/WebContent/index.html create mode 100644 app/v2_java/WebContent/login.html create mode 100644 app/v2_java/WebContent/user.html create mode 100644 app/v2_java/src/org/usi2011/Database.java create mode 100644 app/v2_java/src/org/usi2011/Question.java create mode 100644 app/v2_java/src/org/usi2011/User.java (limited to 'app/v2_java') diff --git a/app/v2_java/.classpath b/app/v2_java/.classpath new file mode 100644 index 0000000..7eda24b --- /dev/null +++ b/app/v2_java/.classpath @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/v2_java/.pmd b/app/v2_java/.pmd new file mode 100644 index 0000000..726c68f --- /dev/null +++ b/app/v2_java/.pmd @@ -0,0 +1,941 @@ + + + false + .ruleset + + + AvoidDecimalLiteralsInBigDecimalConstructor + Basic Rules + + + AvoidMultipleUnaryOperators + Basic Rules + + + AvoidThreadGroup + Basic Rules + + + AvoidUsingHardCodedIP + Basic Rules + + + AvoidUsingOctalValues + Basic Rules + + + BigIntegerInstantiation + Basic Rules + + + BooleanInstantiation + Basic Rules + + + BrokenNullCheck + Basic Rules + + + CheckResultSet + Basic Rules + + + ClassCastExceptionWithToArray + Basic Rules + + + CollapsibleIfStatements + Basic Rules + + + DoubleCheckedLocking + Basic Rules + + + EmptyCatchBlock + Basic Rules + + + EmptyFinallyBlock + Basic Rules + + + EmptyIfStmt + Basic Rules + + + EmptyInitializer + Basic Rules + + + EmptyStatementNotInLoop + Basic Rules + + + EmptyStaticInitializer + Basic Rules + + + EmptySwitchStatements + Basic Rules + + + EmptySynchronizedBlock + Basic Rules + + + EmptyTryBlock + Basic Rules + + + EmptyWhileStmt + Basic Rules + + + ForLoopShouldBeWhileLoop + Basic Rules + + + JumbledIncrementer + Basic Rules + + + MisplacedNullCheck + Basic Rules + + + OverrideBothEqualsAndHashcode + Basic Rules + + + ReturnFromFinallyBlock + Basic Rules + + + UnconditionalIfStatement + Basic Rules + + + UnnecessaryConversionTemporary + Basic Rules + + + UnnecessaryFinalModifier + Basic Rules + + + UnnecessaryReturn + Basic Rules + + + UnusedNullCheckInEquals + Basic Rules + + + UselessOperationOnImmutable + Basic Rules + + + UselessOverridingMethod + Basic Rules + + + ForLoopsMustUseBraces + Braces Rules + + + IfElseStmtsMustUseBraces + Braces Rules + + + IfStmtsMustUseBraces + Braces Rules + + + WhileLoopsMustUseBraces + Braces Rules + + + CloneThrowsCloneNotSupportedException + Clone Implementation Rules + + + ProperCloneImplementation + Clone Implementation Rules + + + CyclomaticComplexity + Code Size Rules + + + ExcessiveClassLength + Code Size Rules + + + ExcessiveMethodLength + Code Size Rules + + + ExcessiveParameterList + Code Size Rules + + + ExcessivePublicCount + Code Size Rules + + + NcssConstructorCount + Code Size Rules + + + NcssMethodCount + Code Size Rules + + + NcssTypeCount + Code Size Rules + + + NPathComplexity + Code Size Rules + + + TooManyFields + Code Size Rules + + + TooManyMethods + Code Size Rules + + + AssignmentInOperand + Controversial Rules + + + AtLeastOneConstructor + Controversial Rules + + + AvoidAccessibilityAlteration + Controversial Rules + + + AvoidFinalLocalVariable + Controversial Rules + + + AvoidUsingNativeCode + Controversial Rules + + + AvoidUsingShortType + Controversial Rules + + + AvoidUsingVolatile + Controversial Rules + + + BooleanInversion + Controversial Rules + + + CallSuperInConstructor + Controversial Rules + + + DataflowAnomalyAnalysis + Controversial Rules + + + DefaultPackage + Controversial Rules + + + DoNotCallGarbageCollectionExplicitly + Controversial Rules + + + DontImportSun + Controversial Rules + + + NullAssignment + Controversial Rules + + + OnlyOneReturn + Controversial Rules + + + SuspiciousOctalEscape + Controversial Rules + + + UnnecessaryConstructor + Controversial Rules + + + UnnecessaryParentheses + Controversial Rules + + + UnusedModifier + Controversial Rules + + + CouplingBetweenObjects + Coupling Rules + + + ExcessiveImports + Coupling Rules + + + AbstractClassWithoutAbstractMethod + Design Rules + + + AbstractClassWithoutAnyMethod + Design Rules + + + AccessorClassGeneration + Design Rules + + + AssignmentToNonFinalStatic + Design Rules + + + AvoidConstantsInterface + Design Rules + + + AvoidDeeplyNestedIfStmts + Design Rules + + + AvoidInstanceofChecksInCatchClause + Design Rules + + + AvoidProtectedFieldInFinalClass + Design Rules + + + AvoidReassigningParameters + Design Rules + + + AvoidSynchronizedAtMethodLevel + Design Rules + + + BadComparison + Design Rules + + + ClassWithOnlyPrivateConstructorsShouldBeFinal + Design Rules + + + CloseResource + Design Rules + + + CompareObjectsWithEquals + Design Rules + + + ConfusingTernary + Design Rules + + + ConstructorCallsOverridableMethod + Design Rules + + + DefaultLabelNotLastInSwitchStmt + Design Rules + + + EmptyMethodInAbstractClassShouldBeAbstract + Design Rules + + + EqualsNull + Design Rules + + + FinalFieldCouldBeStatic + Design Rules + + + IdempotentOperations + Design Rules + + + ImmutableField + Design Rules + + + InstantiationToGetClass + Design Rules + + + MissingBreakInSwitch + Design Rules + + + MissingStaticMethodInNonInstantiatableClass + Design Rules + + + NonCaseLabelInSwitchStatement + Design Rules + + + NonStaticInitializer + Design Rules + + + NonThreadSafeSingleton + Design Rules + + + OptimizableToArrayCall + Design Rules + + + PositionLiteralsFirstInComparisons + Design Rules + + + PreserveStackTrace + Design Rules + + + ReturnEmptyArrayRatherThanNull + Design Rules + + + SimpleDateFormatNeedsLocale + Design Rules + + + SimplifyBooleanExpressions + Design Rules + + + SimplifyBooleanReturns + Design Rules + + + SimplifyConditional + Design Rules + + + SingularField + Design Rules + + + SwitchDensity + Design Rules + + + SwitchStmtsShouldHaveDefault + Design Rules + + + TooFewBranchesForASwitchStatement + Design Rules + + + UncommentedEmptyConstructor + Design Rules + + + UncommentedEmptyMethod + Design Rules + + + UnnecessaryLocalBeforeReturn + Design Rules + + + UnsynchronizedStaticDateFormatter + Design Rules + + + UseCollectionIsEmpty + Design Rules + + + UseLocaleWithCaseConversions + Design Rules + + + UseNotifyAllInsteadOfNotify + Design Rules + + + UseSingleton + Design Rules + + + AvoidCallingFinalize + Finalizer Rules + + + EmptyFinalizer + Finalizer Rules + + + FinalizeDoesNotCallSuperFinalize + Finalizer Rules + + + FinalizeOnlyCallsSuperFinalize + Finalizer Rules + + + FinalizeOverloaded + Finalizer Rules + + + FinalizeShouldBeProtected + Finalizer Rules + + + DontImportJavaLang + Import Statement Rules + + + DuplicateImports + Import Statement Rules + + + ImportFromSamePackage + Import Statement Rules + + + TooManyStaticImports + Import Statement Rules + + + DoNotCallSystemExit + J2EE Rules + + + DoNotUseThreads + J2EE Rules + + + LocalHomeNamingConvention + J2EE Rules + + + LocalInterfaceSessionNamingConvention + J2EE Rules + + + MDBAndSessionBeanNamingConvention + J2EE Rules + + + RemoteInterfaceNamingConvention + J2EE Rules + + + RemoteSessionInterfaceNamingConvention + J2EE Rules + + + StaticEJBFieldShouldBeFinal + J2EE Rules + + + UseProperClassLoader + J2EE Rules + + + ProperLogger + Jakarta Commons Logging Rules + + + UseCorrectExceptionLogging + Jakarta Commons Logging Rules + + + AvoidPrintStackTrace + Java Logging Rules + + + LoggerIsNotStaticFinal + Java Logging Rules + + + MoreThanOneLogger + Java Logging Rules + + + SystemPrintln + Java Logging Rules + + + BeanMembersShouldSerialize + JavaBean Rules + + + MissingSerialVersionUID + JavaBean Rules + + + JUnitAssertionsShouldIncludeMessage + JUnit Rules + + + JUnitSpelling + JUnit Rules + + + JUnitStaticSuite + JUnit Rules + + + JUnitTestsShouldIncludeAssert + JUnit Rules + + + SimplifyBooleanAssertion + JUnit Rules + + + TestClassWithoutTestCases + JUnit Rules + + + UnnecessaryBooleanAssertion + JUnit Rules + + + UseAssertEqualsInsteadOfAssertTrue + JUnit Rules + + + UseAssertNullInsteadOfAssertTrue + JUnit Rules + + + UseAssertSameInsteadOfAssertTrue + JUnit Rules + + + AvoidAssertAsIdentifier + Migration Rules + + + AvoidEnumAsIdentifier + Migration Rules + + + ByteInstantiation + Migration Rules + + + IntegerInstantiation + Migration Rules + + + JUnit4SuitesShouldUseSuiteAnnotation + Migration Rules + + + JUnit4TestShouldUseAfterAnnotation + Migration Rules + + + JUnit4TestShouldUseBeforeAnnotation + Migration Rules + + + JUnit4TestShouldUseTestAnnotation + Migration Rules + + + JUnitUseExpected + Migration Rules + + + LongInstantiation + Migration Rules + + + ReplaceEnumerationWithIterator + Migration Rules + + + ReplaceHashtableWithMap + Migration Rules + + + ReplaceVectorWithList + Migration Rules + + + ShortInstantiation + Migration Rules + + + AbstractNaming + Naming Rules + + + AvoidDollarSigns + Naming Rules + + + AvoidFieldNameMatchingMethodName + Naming Rules + + + AvoidFieldNameMatchingTypeName + Naming Rules + + + BooleanGetMethodName + Naming Rules + + + ClassNamingConventions + Naming Rules + + + LongVariable + Naming Rules + + + MethodNamingConventions + Naming Rules + + + MethodWithSameNameAsEnclosingClass + Naming Rules + + + MisleadingVariableName + Naming Rules + + + NoPackage + Naming Rules + + + PackageCase + Naming Rules + + + ShortMethodName + Naming Rules + + + ShortVariable + Naming Rules + + + SuspiciousConstantFieldName + Naming Rules + + + SuspiciousEqualsMethodName + Naming Rules + + + SuspiciousHashcodeMethodName + Naming Rules + + + VariableNamingConventions + Naming Rules + + + AddEmptyString + Optimization Rules + + + AvoidArrayLoops + Optimization Rules + + + AvoidInstantiatingObjectsInLoops + Optimization Rules + + + LocalVariableCouldBeFinal + Optimization Rules + + + MethodArgumentCouldBeFinal + Optimization Rules + + + SimplifyStartsWith + Optimization Rules + + + UnnecessaryWrapperObjectCreation + Optimization Rules + + + UseArrayListInsteadOfVector + Optimization Rules + + + UseArraysAsList + Optimization Rules + + + UseStringBufferForStringAppends + Optimization Rules + + + ArrayIsStoredDirectly + Security Code Guidelines + + + MethodReturnsInternalArray + Security Code Guidelines + + + AvoidCatchingNPE + Strict Exception Rules + + + AvoidCatchingThrowable + Strict Exception Rules + + + AvoidRethrowingException + Strict Exception Rules + + + AvoidThrowingNewInstanceOfSameException + Strict Exception Rules + + + AvoidThrowingNullPointerException + Strict Exception Rules + + + AvoidThrowingRawExceptionTypes + Strict Exception Rules + + + DoNotExtendJavaLangError + Strict Exception Rules + + + DoNotThrowExceptionInFinally + Strict Exception Rules + + + ExceptionAsFlowControl + Strict Exception Rules + + + AppendCharacterWithChar + String and StringBuffer Rules + + + AvoidDuplicateLiterals + String and StringBuffer Rules + + + AvoidStringBufferField + String and StringBuffer Rules + + + ConsecutiveLiteralAppends + String and StringBuffer Rules + + + InefficientEmptyStringCheck + String and StringBuffer Rules + + + InefficientStringBuffering + String and StringBuffer Rules + + + InsufficientStringBufferDeclaration + String and StringBuffer Rules + + + StringBufferInstantiationWithChar + String and StringBuffer Rules + + + StringInstantiation + String and StringBuffer Rules + + + StringToString + String and StringBuffer Rules + + + UnnecessaryCaseChange + String and StringBuffer Rules + + + UseEqualsToCompareStrings + String and StringBuffer Rules + + + UseIndexOfChar + String and StringBuffer Rules + + + UselessStringValueOf + String and StringBuffer Rules + + + UseStringBufferLength + String and StringBuffer Rules + + + CloneMethodMustImplementCloneable + Type Resolution Rules + + + LooseCoupling + Type Resolution Rules + + + SignatureDeclareThrowsException + Type Resolution Rules + + + UnusedImports + Type Resolution Rules + + + UnusedFormalParameter + Unused Code Rules + + + UnusedLocalVariable + Unused Code Rules + + + UnusedPrivateField + Unused Code Rules + + + UnusedPrivateMethod + Unused Code Rules + + + false + true + diff --git a/app/v2_java/.project b/app/v2_java/.project new file mode 100644 index 0000000..a096e18 --- /dev/null +++ b/app/v2_java/.project @@ -0,0 +1,36 @@ + + + usi2011 + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/app/v2_java/.settings/.jsdtscope b/app/v2_java/.settings/.jsdtscope new file mode 100644 index 0000000..f40dd98 --- /dev/null +++ b/app/v2_java/.settings/.jsdtscope @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/app/v2_java/.settings/org.eclipse.jdt.core.prefs b/app/v2_java/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..68097b4 --- /dev/null +++ b/app/v2_java/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Sat Jan 22 14:50:35 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/app/v2_java/.settings/org.eclipse.wst.common.component b/app/v2_java/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..f7b9782 --- /dev/null +++ b/app/v2_java/.settings/org.eclipse.wst.common.component @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/app/v2_java/.settings/org.eclipse.wst.common.project.facet.core.xml b/app/v2_java/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..2f33901 --- /dev/null +++ b/app/v2_java/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.container b/app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.name b/app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/app/v2_java/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/app/v2_java/WebContent/META-INF/MANIFEST.MF b/app/v2_java/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/app/v2_java/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/app/v2_java/WebContent/WEB-INF/web.xml b/app/v2_java/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..1ee7e79 --- /dev/null +++ b/app/v2_java/WebContent/WEB-INF/web.xml @@ -0,0 +1,31 @@ + + + usi2011 + + + + Question + Question + org.usi2011.Question + + + + + User + User + org.usi2011.User + + + Question + /api/question/* + + + User + /api/user/ + + + index.html + + diff --git a/app/v2_java/WebContent/game.html b/app/v2_java/WebContent/game.html new file mode 100644 index 0000000..f53b9ad --- /dev/null +++ b/app/v2_java/WebContent/game.html @@ -0,0 +1,22 @@ + + + + + +
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/app/v2_java/WebContent/index.html b/app/v2_java/WebContent/index.html new file mode 100644 index 0000000..46b3200 --- /dev/null +++ b/app/v2_java/WebContent/index.html @@ -0,0 +1,10 @@ + + + + +Insert title here + + +dsfsdfsdfsdfsfsdfs + + \ No newline at end of file diff --git a/app/v2_java/WebContent/login.html b/app/v2_java/WebContent/login.html new file mode 100644 index 0000000..a24ea4b --- /dev/null +++ b/app/v2_java/WebContent/login.html @@ -0,0 +1,20 @@ + + + + + +
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/app/v2_java/WebContent/user.html b/app/v2_java/WebContent/user.html new file mode 100644 index 0000000..e1be8e5 --- /dev/null +++ b/app/v2_java/WebContent/user.html @@ -0,0 +1,28 @@ + + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/app/v2_java/src/org/usi2011/Database.java b/app/v2_java/src/org/usi2011/Database.java new file mode 100644 index 0000000..6ebb63a --- /dev/null +++ b/app/v2_java/src/org/usi2011/Database.java @@ -0,0 +1,73 @@ +package org.usi2011; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +/** + * @author XKHM6852 + * + */ +public final class Database { + + private static Connection connection; + + /** */ + public static Connection getConnection() { + if (connection == null) { + createDatabase(); + } + return connection; + } + + private static void createDatabase() { + try { + connection = DriverManager.getConnection("jdbc:hsqldb:mem:aname", + "sa", ""); + String query = "DROP TABLE game; CREATE TABLE game ( " + + " id INT NOT NULL PRIMARY KEY, " + + " longpollingduration INT NOT NULL, " + + " nbusersthreshold INT NOT NULL," + + " questiontimeframe INT NOT NULL," + + " nbquestions INT NOT NULL" + ");"; + + Statement statement = connection.createStatement(); + ResultSet resultset = statement.executeQuery(query); + connection.commit(); + createUser(); + + } catch (SQLException e) { + + System.out.println("SQL Exception " + e.getMessage()); + } + } + + private static void createUser() { + /* + `id` int(11) NOT NULL AUTO_INCREMENT, + `firstname` varchar(255) COLLATE utf8_bin NOT NULL, + `lastname` varchar(255) COLLATE utf8_bin NOT NULL, + `mail` varchar(255) COLLATE utf8_bin NOT NULL, + `password` varchar(255) COLLATE utf8_bin NOT NULL, + */ + try { + String query = "DROP TABLE user; CREATE TABLE user ( " + + " id INT GENERATED BY DEFAULT AS IDENTITY, " + + " firstname VARCHAR NOT NULL, " + + " lastname VARCHAR NOT NULL," + + " mail VARCHAR NOT NULL," + + " password VARCHAR NOT NULL" + ");"; + + Statement statement = connection.createStatement(); + ResultSet resultset = statement.executeQuery(query); + connection.commit(); + + } catch (SQLException e) { + + System.out.println("SQL Exception " + e.getMessage()); + } + } + +} diff --git a/app/v2_java/src/org/usi2011/Question.java b/app/v2_java/src/org/usi2011/Question.java new file mode 100644 index 0000000..0c391d3 --- /dev/null +++ b/app/v2_java/src/org/usi2011/Question.java @@ -0,0 +1,67 @@ +package org.usi2011; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class question + */ +public class Question extends HttpServlet { + private static final long serialVersionUID = 1L; + private Connection connection; + /** + * Default constructor. + */ + public Question() { + super(); + connection = Database.getConnection(); + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + ServletOutputStream out = response.getOutputStream(); + + try { + String query = "INSERT INTO game VALUES (1, 2, 3, 4, 5)"; + Statement statement = connection.createStatement(); + ResultSet resultset = statement.executeQuery(query); + query = "SELECT * FROM game"; + statement = connection.createStatement(); + resultset = statement.executeQuery(query); + while (resultset.next()) { + out.println(resultset.getString(1)); + } + } catch (SQLException e) { + response.sendError(400); + } + + + out.println("hello world"); + out.println(request.getRequestURI()); + + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doPost(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + } + +} diff --git a/app/v2_java/src/org/usi2011/User.java b/app/v2_java/src/org/usi2011/User.java new file mode 100644 index 0000000..091b4eb --- /dev/null +++ b/app/v2_java/src/org/usi2011/User.java @@ -0,0 +1,56 @@ +package org.usi2011; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class User + */ +public class User extends HttpServlet { + private static final long serialVersionUID = 1L; + private Connection connection; + /** + * @see HttpServlet#HttpServlet() + */ + public User() { + super(); + connection = Database.getConnection(); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + String firstname = request.getParameter("firstname"); + String lastname = request.getParameter("lastname"); + String mail = request.getParameter("mail"); + String password = request.getParameter("password"); + + System.out.println(firstname); + System.out.println(lastname); + System.out.println(mail); + System.out.println(password); + + String query = "INSERT INTO game(firstname, lastname, mail) VALUES ('"+firstname+"', '"+lastname+"', '"+mail+"', '"+password+"')"; + Statement statement = connection.createStatement(); + ResultSet resultset = statement.executeQuery(query); + + response.setStatus(response.SC_CREATED); + + } catch (SQLException e) { + System.out.println(e.getMessage()); + response.sendError(400); + } + } + +} -- cgit v1.2.3