Reputation: 97
I have the following simple form element:
<form action="Test" method="POST" enctype="multipart/form-data">
<input type="text" name="vorname" title="Vorname"></input>
<input type="text" name="nachname" title="Nachname"></input>
<input
type="submit"></input>
</form>
my POST method in the Servlet looks the following way:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(request.getParameter("vorname"));
String var_Name = request.getParameter("nachname");
String var_Vorname = request.getParameter("vorname");
try {
con = Datenbankverbindung();
if (con != null) {
System.out.println("Verbunden");
stmt = con.prepareStatement("insert into ktzvtest (Name,
Vorname) values (?, ?)");
stmt.setString(1, var_Name);
stmt.setString(2, var_Vorname);
stmt.executeUpdate();
System.out.print("erfolgreich");
}
} catch (Exception e) {
e.printStackTrace();
}
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
So the two variables var_Name and var_Vorname are alway NULL. What's the problem ?
Upvotes: 0
Views: 27
Reputation: 18965
Because you use enctype="multipart/form-data"
you can not retrieve parameters using plain request.getParameter
.
Remove enctype="multipart/form-data"
it will work
Upvotes: 1