	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		Session session = HibernateSessionHelper.getSession();
		Template template = TemplateFactory.getTemplate(request, response);
		PrintWriter out = response.getWriter();
		TaskDAOIf taskDAO = DAOFactory.TaskDAOIf(session);
		Task task = taskDAO.getTask(Util.parseInteger(request.getParameter("taskid"), 0));
		if (task == null) {
			template.printTemplateHeader("Aufgabe nicht gefunden");
			out.println("<div class=mid><a href=\"" + response.encodeURL("?") + "\">zur �bersicht</a></div>");
			template.printTemplateFooter();
			return;
		}
		ParticipationDAOIf participationDAO = DAOFactory.ParticipationDAOIf(session);
		Participation studentParticipation = participationDAO.getParticipation(new SessionAdapter(request).getUser(session), task.getLecture());
		if (studentParticipation == null) {
			template.printTemplateHeader("Ung�ltige Anfrage");
			out.println("<div class=mid>Sie sind kein Teilnehmer dieser Veranstaltung.</div>");
			out.println("<div class=mid><a href=\"" + response.encodeURL("Overview") + "\">zur �bersicht</a></div>");
			template.printTemplateFooter();
			return;
		}
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);
		int partnerID = 0;
		int uploadFor = 0;
		List<FileItem> items = null;
		if (!isMultipart) {
			partnerID = Util.parseInteger(request.getParameter("partnerid"), 0);
		} else {
			FileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			try {
				items = upload.parseRequest(request);
			} catch (FileUploadException e) {
				response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
				return;
			}
			Iterator<FileItem> iter = items.iterator();
			while (iter.hasNext()) {
				FileItem item = iter.next();
				if (item.isFormField() && "partnerid".equals(item.getFieldName())) {
					partnerID = Util.parseInteger(item.getString(), 0);
				} else if (item.isFormField() && "uploadFor".equals(item.getFieldName())) {
					uploadFor = Util.parseInteger(item.getString(), 0);
				}
			}
		}
		if (uploadFor > 0) {
			if (!(studentParticipation.getRoleType() == ParticipationRole.ADVISOR || (task.isTutorsCanUploadFiles() && studentParticipation.getRoleType() == ParticipationRole.TUTOR))) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Sie sind nicht berechtigt bei dieser Veranstaltung Dateien f�r Studenten hochzuladen.</div>");
				out.println("<div class=mid><a href=\"" + response.encodeURL("Overview") + "\">zur �bersicht</a></div>");
				template.printTemplateFooter();
				return;
			}
			studentParticipation = participationDAO.getParticipation(uploadFor);
			if (studentParticipation == null || studentParticipation.getLecture().getId() != task.getLecture().getId()) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Der gew�hlte Student ist kein Teilnehmer dieser Veranstaltung.</div>");
				out.println("<div class=mid><a href=\"" + response.encodeURL("Overview") + "\">zur �bersicht</a></div>");
				template.printTemplateFooter();
				return;
			}
			if (task.isShowTextArea() == false && "-".equals(task.getFilenameRegexp())) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Das Einsenden von L�sungen ist f�r diese Aufgabe deaktiviert.</div>");
				template.printTemplateFooter();
				return;
			}
		} else {
			if (studentParticipation.getRoleType() == ParticipationRole.ADVISOR || studentParticipation.getRoleType() == ParticipationRole.TUTOR) {
				request.setAttribute("title", "Betreuer und Tutoren k�nnen keine eigenen L�sungen einsenden.");
				request.getRequestDispatcher("MessageView").forward(request, response);
				return;
			}
			if (task.getStart().after(Util.correctTimezone(new Date()))) {
				request.setAttribute("title", "Abgabe nicht gefunden");
				request.getRequestDispatcher("MessageView").forward(request, response);
				return;
			}
			if (task.getDeadline().before(Util.correctTimezone(new Date()))) {
				request.setAttribute("title", "Abgabe nicht mehr m�glich");
				request.getRequestDispatcher("MessageView").forward(request, response);
				return;
			}
			if (isMultipart && "-".equals(task.getFilenameRegexp())) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Dateiupload ist f�r diese Aufgabe deaktiviert.</div>");
				template.printTemplateFooter();
				return;
			} else if (!isMultipart && !task.isShowTextArea()) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Textl�sungen sind f�r diese Aufgabe deaktiviert.</div>");
				template.printTemplateFooter();
				return;
			}
		}
		SubmissionDAOIf submissionDAO = DAOFactory.SubmissionDAOIf(session);
		Transaction tx = session.beginTransaction();
		Submission submission = submissionDAO.createSubmission(task, studentParticipation);
		if (partnerID > 0) {
			Participation partnerParticipation = participationDAO.getParticipation(partnerID);
			if (submission.getSubmitters().size() < 2 && partnerParticipation != null && partnerParticipation.getLecture().getId() == task.getLecture().getId() && submissionDAO.getSubmissionLocked(task, partnerParticipation.getUser()) == null) {
				submission.getSubmitters().add(partnerParticipation);
				session.update(submission);
			} else {
				tx.rollback();
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Der ausgew�hlte Partner hat bereits eine eigene Abgabe initiiert oder Sie haben bereits einen Partner ausgew�hlt.</div>");
				template.printTemplateFooter();
				return;
			}
		}
		ContextAdapter contextAdapter = new ContextAdapter(getServletContext());
		File path = new File(contextAdapter.getDataPath().getAbsolutePath() + System.getProperty("file.separator") + task.getLecture().getId() + System.getProperty("file.separator") + task.getTaskid() + System.getProperty("file.separator") + submission.getSubmissionid() + System.getProperty("file.separator"));
		if (path.exists() == false) {
			path.mkdirs();
		}
		if (isMultipart) {
			Iterator<FileItem> iter = items.iterator();
			while (iter.hasNext()) {
				FileItem item = iter.next();
				if (!item.isFormField()) {
					if (item.getName().toLowerCase().endsWith(".zip") || item.getName().toLowerCase().endsWith(".jar")) {
						ZipInputStream zipFile;
						Pattern pattern = Pattern.compile("([\\/a-zA-Z0-9_.-]+)$");
						try {
							zipFile = new ZipInputStream(item.getInputStream());
							ZipEntry entry = null;
							while ((entry = zipFile.getNextEntry()) != null) {
								if (entry.getName().contains("..")) {
									continue;
								}
								StringBuffer submittedFileName = new StringBuffer(entry.getName());
								if (!pattern.matcher(submittedFileName).matches()) {
									System.out.println("Ignored entry: " + submittedFileName);
									continue;
								}
								if (entry.isDirectory() == false && !entry.getName().toLowerCase().endsWith(".class")) {
									if (submittedFileName.lastIndexOf(".") > 0) {
										int lastDot = submittedFileName.lastIndexOf(".");
										submittedFileName.replace(lastDot, submittedFileName.length(), submittedFileName.subSequence(lastDot, submittedFileName.length()).toString().toLowerCase());
									}
									File fileToCreate = new File(path, submittedFileName.toString());
									if (!fileToCreate.getParentFile().exists()) {
										fileToCreate.getParentFile().mkdirs();
									}
									copyInputStream(zipFile, new BufferedOutputStream(new FileOutputStream(fileToCreate)));
								}
							}
							zipFile.close();
						} catch (IOException e) {
							Util.recursiveDeleteEmptySubDirectories(path);
							tx.rollback();
							System.out.println(e.getMessage());
							e.printStackTrace();
							template.printTemplateHeader("Ung�ltige Anfrage");
							out.println("Problem beim entpacken der .zip-Datei.");
							template.printTemplateFooter();
							return;
						}
					} else {
						Pattern pattern;
						if (task.getFilenameRegexp() == null || task.getFilenameRegexp().isEmpty() || uploadFor > 0) {
							pattern = Pattern.compile(".*?(?:\\\\|/)?([a-zA-Z0-9_.-]+)$");
						} else {
							pattern = Pattern.compile(".*?(?:\\\\|/)?(" + task.getFilenameRegexp() + ")$");
						}
						StringBuffer submittedFileName = new StringBuffer(item.getName());
						if (submittedFileName.lastIndexOf(".") > 0) {
							int lastDot = submittedFileName.lastIndexOf(".");
							submittedFileName.replace(lastDot, submittedFileName.length(), submittedFileName.subSequence(lastDot, submittedFileName.length()).toString().toLowerCase());
						}
						Matcher m = pattern.matcher(submittedFileName);
						if (!m.matches()) {
							tx.rollback();
							template.printTemplateHeader("Ung�ltige Anfrage");
							out.println("Dateiname ung�ltig bzw. entspricht nicht der Vorgabe (ist ein Klassenname vorgegeben, so muss die Datei genauso hei�en).<br>Tipp: Nur A-Z, a-z, 0-9, ., - und _ sind erlaubt.");
							template.printTemplateFooter();
							return;
						}
						String fileName = m.group(1);
						File uploadedFile = new File(path, fileName);
						if (fileName.toLowerCase().endsWith(".java")) {
							uploadedFile = File.createTempFile("upload", null, path);
						}
						try {
							item.write(uploadedFile);
						} catch (Exception e) {
							e.printStackTrace();
						}
						if (fileName.toLowerCase().endsWith(".java")) {
							NormalizerIf stripComments = new StripCommentsNormalizer();
							StringBuffer javaFileContents = stripComments.normalize(Util.loadFile(uploadedFile));
							Pattern packagePattern = Pattern.compile(".*package\\s+([a-zA-Z$]([a-zA-Z0-9_$]|\\.[a-zA-Z0-9_$])*)\\s*;.*", Pattern.DOTALL);
							Matcher packageMatcher = packagePattern.matcher(javaFileContents);
							if (packageMatcher.matches()) {
								String packageName = packageMatcher.group(1).replace(".", System.getProperty("file.separator"));
								File packageDirectory = new File(path, packageName);
								packageDirectory.mkdirs();
								uploadedFile.renameTo(new File(packageDirectory, fileName));
							} else {
								uploadedFile.renameTo(new File(path, fileName));
							}
						}
					}
					submission.setLastModified(new Date());
					submissionDAO.saveSubmission(submission);
					Util.recursiveDeleteEmptyDirectories(path);
					tx.commit();
					new LogDAO(session).createLogEntry(studentParticipation.getUser(), null, task, LogAction.UPLOAD, null, null);
					response.sendRedirect(response.encodeRedirectURL("ShowTask?taskid=" + task.getTaskid()));
					return;
				}
			}
			tx.rollback();
			out.println("Problem: Keine Abgabedaten gefunden.");
		} else if (request.getParameter("textsolution") != null) {
			File uploadedFile = new File(path, "textloesung.txt");
			FileWriter fileWriter = new FileWriter(uploadedFile);
			fileWriter.write(request.getParameter("textsolution"));
			fileWriter.flush();
			fileWriter.close();
			submission.setLastModified(new Date());
			submissionDAO.saveSubmission(submission);
			tx.commit();
			response.sendRedirect(response.encodeRedirectURL("ShowTask?taskid=" + task.getTaskid()));
		} else {
			tx.rollback();
			out.println("Problem: Keine Abgabedaten gefunden.");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		Session session = HibernateSessionHelper.getSession();
		Template template = TemplateFactory.getTemplate(request, response);
		PrintWriter out = response.getWriter();
		TaskDAOIf taskDAO = DAOFactory.TaskDAOIf(session);
		Task task = taskDAO.getTask(Util.parseInteger(request.getParameter("taskid"), 0));
		if (task == null) {
			template.printTemplateHeader("Aufgabe nicht gefunden");
			out.println("<div class=mid><a href=\"" + response.encodeURL("?") + "\">zur �bersicht</a></div>");
			template.printTemplateFooter();
			return;
		}
		ParticipationDAOIf participationDAO = DAOFactory.ParticipationDAOIf(session);
		Participation studentParticipation = participationDAO.getParticipation(new SessionAdapter(request).getUser(session), task.getLecture());
		if (studentParticipation == null) {
			template.printTemplateHeader("Ung�ltige Anfrage");
			out.println("<div class=mid>Sie sind kein Teilnehmer dieser Veranstaltung.</div>");
			out.println("<div class=mid><a href=\"" + response.encodeURL("Overview") + "\">zur �bersicht</a></div>");
			template.printTemplateFooter();
			return;
		}
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);
		int partnerID = 0;
		int uploadFor = 0;
		List<FileItem> items = null;
		if (!isMultipart) {
			partnerID = Util.parseInteger(request.getParameter("partnerid"), 0);
		} else {
			FileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			try {
				items = upload.parseRequest(request);
			} catch (FileUploadException e) {
				response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
				return;
			}
			Iterator<FileItem> iter = items.iterator();
			while (iter.hasNext()) {
				FileItem item = iter.next();
				if (item.isFormField() && "partnerid".equals(item.getFieldName())) {
					partnerID = Util.parseInteger(item.getString(), 0);
				} else if (item.isFormField() && "uploadFor".equals(item.getFieldName())) {
					uploadFor = Util.parseInteger(item.getString(), 0);
				}
			}
		}
		if (uploadFor > 0) {
			if (!(studentParticipation.getRoleType() == ParticipationRole.ADVISOR || (task.isTutorsCanUploadFiles() && studentParticipation.getRoleType() == ParticipationRole.TUTOR))) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Sie sind nicht berechtigt bei dieser Veranstaltung Dateien f�r Studenten hochzuladen.</div>");
				out.println("<div class=mid><a href=\"" + response.encodeURL("Overview") + "\">zur �bersicht</a></div>");
				template.printTemplateFooter();
				return;
			}
			studentParticipation = participationDAO.getParticipation(uploadFor);
			if (studentParticipation == null || studentParticipation.getLecture().getId() != task.getLecture().getId()) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Der gew�hlte Student ist kein Teilnehmer dieser Veranstaltung.</div>");
				out.println("<div class=mid><a href=\"" + response.encodeURL("Overview") + "\">zur �bersicht</a></div>");
				template.printTemplateFooter();
				return;
			}
			if (task.isShowTextArea() == false && "-".equals(task.getFilenameRegexp())) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Das Einsenden von L�sungen ist f�r diese Aufgabe deaktiviert.</div>");
				template.printTemplateFooter();
				return;
			}
		} else {
			if (studentParticipation.getRoleType() == ParticipationRole.ADVISOR || studentParticipation.getRoleType() == ParticipationRole.TUTOR) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Betreuer und Tutoren k�nnen keine eigenen L�sungen einsenden.</div>");
				template.printTemplateFooter();
				return;
			}
			if (task.getStart().after(Util.correctTimezone(new Date()))) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Abgabe nicht gefunden.</div>");
				template.printTemplateFooter();
				return;
			}
			if (task.getDeadline().before(Util.correctTimezone(new Date()))) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Abgabe nicht mehr m�glich.</div>");
				template.printTemplateFooter();
				return;
			}
			if (isMultipart && "-".equals(task.getFilenameRegexp())) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Dateiupload ist f�r diese Aufgabe deaktiviert.</div>");
				template.printTemplateFooter();
				return;
			} else if (!isMultipart && !task.isShowTextArea()) {
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Textl�sungen sind f�r diese Aufgabe deaktiviert.</div>");
				template.printTemplateFooter();
				return;
			}
		}
		SubmissionDAOIf submissionDAO = DAOFactory.SubmissionDAOIf(session);
		Transaction tx = session.beginTransaction();
		Submission submission = submissionDAO.createSubmission(task, studentParticipation);
		if (partnerID > 0) {
			Participation partnerParticipation = participationDAO.getParticipation(partnerID);
			if (submission.getSubmitters().size() < 2 && partnerParticipation != null && partnerParticipation.getLecture().getId() == task.getLecture().getId() && submissionDAO.getSubmissionLocked(task, partnerParticipation.getUser()) == null) {
				submission.getSubmitters().add(partnerParticipation);
				session.update(submission);
			} else {
				tx.rollback();
				template.printTemplateHeader("Ung�ltige Anfrage");
				out.println("<div class=mid>Der ausgew�hlte Partner hat bereits eine eigene Abgabe initiiert oder Sie haben bereits einen Partner ausgew�hlt.</div>");
				template.printTemplateFooter();
				return;
			}
		}
		ContextAdapter contextAdapter = new ContextAdapter(getServletContext());
		File path = new File(contextAdapter.getDataPath().getAbsolutePath() + System.getProperty("file.separator") + task.getLecture().getId() + System.getProperty("file.separator") + task.getTaskid() + System.getProperty("file.separator") + submission.getSubmissionid() + System.getProperty("file.separator"));
		if (path.exists() == false) {
			path.mkdirs();
		}
		if (isMultipart) {
			Iterator<FileItem> iter = items.iterator();
			while (iter.hasNext()) {
				FileItem item = iter.next();
				if (!item.isFormField()) {
					if (item.getName().toLowerCase().endsWith(".zip") || item.getName().toLowerCase().endsWith(".jar")) {
						ZipInputStream zipFile;
						Pattern pattern = Pattern.compile("([\\/a-zA-Z0-9_.-]+)$");
						try {
							zipFile = new ZipInputStream(item.getInputStream());
							ZipEntry entry = null;
							while ((entry = zipFile.getNextEntry()) != null) {
								if (entry.getName().contains("..")) {
									continue;
								}
								StringBuffer submittedFileName = new StringBuffer(entry.getName());
								if (!pattern.matcher(submittedFileName).matches()) {
									System.out.println("Ignored entry: " + submittedFileName);
									continue;
								}
								if (entry.isDirectory() == false && !entry.getName().toLowerCase().endsWith(".class")) {
									if (submittedFileName.lastIndexOf(".") > 0) {
										int lastDot = submittedFileName.lastIndexOf(".");
										submittedFileName.replace(lastDot, submittedFileName.length(), submittedFileName.subSequence(lastDot, submittedFileName.length()).toString().toLowerCase());
									}
									File fileToCreate = new File(path, submittedFileName.toString());
									if (!fileToCreate.getParentFile().exists()) {
										fileToCreate.getParentFile().mkdirs();
									}
									copyInputStream(zipFile, new BufferedOutputStream(new FileOutputStream(fileToCreate)));
								}
							}
							zipFile.close();
						} catch (IOException e) {
							Util.recursiveDeleteEmptySubDirectories(path);
							tx.rollback();
							System.out.println(e.getMessage());
							e.printStackTrace();
							template.printTemplateHeader("Ung�ltige Anfrage");
							out.println("Problem beim entpacken der .zip-Datei.");
							template.printTemplateFooter();
							return;
						}
					} else {
						Pattern pattern;
						if (task.getFilenameRegexp() == null || task.getFilenameRegexp().isEmpty() || uploadFor > 0) {
							pattern = Pattern.compile(".*?(?:\\\\|/)?([a-zA-Z0-9_.-]+)$");
						} else {
							pattern = Pattern.compile(".*?(?:\\\\|/)?(" + task.getFilenameRegexp() + ")$");
						}
						StringBuffer submittedFileName = new StringBuffer(item.getName());
						if (submittedFileName.lastIndexOf(".") > 0) {
							int lastDot = submittedFileName.lastIndexOf(".");
							submittedFileName.replace(lastDot, submittedFileName.length(), submittedFileName.subSequence(lastDot, submittedFileName.length()).toString().toLowerCase());
						}
						Matcher m = pattern.matcher(submittedFileName);
						if (!m.matches()) {
							tx.rollback();
							template.printTemplateHeader("Ung�ltige Anfrage");
							out.println("Dateiname ung�ltig bzw. entspricht nicht der Vorgabe (ist ein Klassenname vorgegeben, so muss die Datei genauso hei�en).<br>Tipp: Nur A-Z, a-z, 0-9, ., - und _ sind erlaubt.");
							template.printTemplateFooter();
							return;
						}
						String fileName = m.group(1);
						File uploadedFile = new File(path, fileName);
						if (fileName.toLowerCase().endsWith(".java")) {
							uploadedFile = File.createTempFile("upload", null, path);
						}
						try {
							item.write(uploadedFile);
						} catch (Exception e) {
							e.printStackTrace();
						}
						if (fileName.toLowerCase().endsWith(".java")) {
							NormalizerIf stripComments = new StripCommentsNormalizer();
							StringBuffer javaFileContents = stripComments.normalize(Util.loadFile(uploadedFile));
							Pattern packagePattern = Pattern.compile(".*package\\s+([a-zA-Z$]([a-zA-Z0-9_$]|\\.[a-zA-Z0-9_$])*)\\s*;.*", Pattern.DOTALL);
							Matcher packageMatcher = packagePattern.matcher(javaFileContents);
							if (packageMatcher.matches()) {
								String packageName = packageMatcher.group(1).replace(".", System.getProperty("file.separator"));
								File packageDirectory = new File(path, packageName);
								packageDirectory.mkdirs();
								uploadedFile.renameTo(new File(packageDirectory, fileName));
							} else {
								uploadedFile.renameTo(new File(path, fileName));
							}
						}
					}
					submission.setLastModified(new Date());
					submissionDAO.saveSubmission(submission);
					Util.recursiveDeleteEmptyDirectories(path);
					tx.commit();
					new LogDAO(session).createLogEntry(studentParticipation.getUser(), null, task, LogAction.UPLOAD, null, null);
					response.sendRedirect(response.encodeRedirectURL("ShowTask?taskid=" + task.getTaskid()));
					return;
				}
			}
			tx.rollback();
			out.println("Problem: Keine Abgabedaten gefunden.");
		} else if (request.getParameter("textsolution") != null) {
			File uploadedFile = new File(path, "textloesung.txt");
			FileWriter fileWriter = new FileWriter(uploadedFile);
			fileWriter.write(request.getParameter("textsolution"));
			fileWriter.flush();
			fileWriter.close();
			submission.setLastModified(new Date());
			submissionDAO.saveSubmission(submission);
			tx.commit();
			response.sendRedirect(response.encodeRedirectURL("ShowTask?taskid=" + task.getTaskid()));
		} else {
			tx.rollback();
			out.println("Problem: Keine Abgabedaten gefunden.");
		}
	}
