Servlet request.getParameter() allways returns null

1

1993maik1993

Huhu leute,

ich habe ein servlet geschrieben welches daten aus der datenbank ausliest und sie dann in einer tabelle ausgibt, problem ist:
Code:
 request.getParameter()
ist immer null...
Code:
package de.XXX.restaurante;

import java.io.IOException;
import java.io.PrintWriter;
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.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Kundenbewertungen extends HttpServlet {

	private String sitepart1, sitepart2 ="", sitepart3, sitepart0, name, meal, mark, comment, data;
	private PrintWriter out;
	private Connection dbConnection;
	private Statement statement;
	private ResultSet res;
	
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws IOException, ServletException {
			response.setContentType("text/html");
			out = response.getWriter();
			name = request.getParameter("name");
			meal = request.getParameter("meal");
			System.out.println(request.getParameter("name") + "|_-_-_|" + request.getParameter("meal"));
			mark = request.getParameter("mark");
			comment = request.getParameter("iscommentthere");
			System.out.println(request.getParameter("mark") + "|_-_-_|" + request.getParameter("iscommentthere"));
			addTableEntryToDB();
			makePage();
		}

	public void addTableEntryToDB() {
		try {
			data = "INSERT INTO tableentries(name, meal, mark, comment)"
					+ "VALUES ('" + name + "','" + meal + "','" + mark + "',"
					+ "'" + comment + "')";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			dbConnection = DriverManager
					.getConnection("jdbc:mysql://127.0.0.1:3306/webprojects?user=root&password=123456");
			statement = dbConnection.createStatement();
			if ((name != null) && (meal != null) && (mark != null) && (comment != null)) {
				statement.executeUpdate(data);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	public void makePage() {
			sitepart1 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " +
					"\"http://www.w3.org/TR/html4/loose.dtd\"><html><head><meta http-equiv" +
					"=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"><title>Ku" +
					"ndenbewertungen unseres Restaurante</title><link type=\"text/css\" re" +
					"l=\"stylesheet\" href=\"style.css\" /></head><body><h2>Bewertungen</h" +
					"2><p>Auf dieser Seite können Sie Bewertungen anderer Gäste einsehen o" +
					"der selbst unser Essen bewerten.<br />Außerdem können Sie ein Komment" +
					"ar zu Ihrer Bewertung abgeben oder vorhandene Kommentare anderer Gäst" +
					"e lesen.</p><table><thead class=\"bewertung\"><tr><td width=\"35%\">K" +
					"undenname</td><td width=\"35%\">Gericht</td><td width=\"15%\">Bewertu" +
					"ng</td><td width=\"15%\">Kommentar vorhanden</td></tr></thead>";
				
			try {
				data = "SELECT * FROM tableentries";
				res = statement.executeQuery(data);
				res.next();
				for (int i = 0; i < res.getRow(); i++) {
					if(i % 2 == 1) {
						sitepart2 = sitepart2 + "<tr id=\"highligthed\"><td>" + res.getString(1) +
						"</td><td>" + res.getString(2) + "</td><td>" + res.getString(3) +
						"</td><td>" + res.getString(4) + "</td></tr>";
					} else if (i % 2 == 0) {
						sitepart2 = sitepart2 + "<tr><td>" + res.getString(1) +
						"</td><td>" + res.getString(2) + "</td><td>" + res.getString(3) +
						"</td><td>" + res.getString(4) + "</td></tr>";
					}
					res.next();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
				
			sitepart3 = "<tr><td><input type=\"text\" name=\"name\" class=\"withborder\" id" +
					"=\"input1\" /></td><td><input type=\"text\" name=\"meal\" class=\"with" +
					"border\" id=\"input2\" /></td><td><select name=\"mark\" id=\"select1\"" +
					"><option value=\"1\">1</option><option value=\"2\">2</option><option v" +
					"alue=\"3\">3</option><option value=\"4\">4</option><option value=\"5\"" +
					">5</option><option value=\"6\">6</option></select></td><td><select nam" +
					"e=\"iscommentthere\" id=\"select2\"><option value=\"Ja\">Ja</option><o" +
					"ption value=\"Nein\">Nein</option></select></td></tr></table><br /><br" +
					" />Kommentar:<br /><textarea name=\"comment\" rows=\"5\" cols=\"40\"><" +
					"/textArea><br /><br /><form method=\"POST\" action=\"Bewertung.html\">" +
					"<input type=\"submit\" name=\"submitmark\" value=\"Bewertung abgeben\"" +
					" /></form><center><p class=\"links\"><a href=\"Impressum.html\">Impres" +
					"sum</a>    <a href=\"Index.html\">Zurück zum Start</a></p></center></b" +
					"ody></html>";
			
			sitepart0 = sitepart1 + sitepart2 + sitepart3;
			out.println(sitepart0);
			sitepart0 = "";
			sitepart1 = "";
			sitepart2 = "";
			sitepart3 = "";
		}
		
	}
 
Zurück