protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection con = null;
ResultSet rst = null;
PreparedStatement pstmt = null;
final String LOAD_BY_ALL = "SELECT * FROM Buecher WHERE Author LIKE ? AND Titel LIKE ? AND Schlagwort LIKE ?";
final String LOAD_BY_AUTHOR = "SELECT * FROM Buecher WHERE Author LIKE ?";
final String LOAD_BY_TITEL = "SELECT * FROM Buecher WHERE Titel LIKE ?";
final String LOAD_BY_SCHLAGWORT = "SELECT * FROM Schlagwort, Buecher WHERE Schlagwort.Tags LIKE ? AND Buecher.Tag_ID = Schlagwort.Schlagwort_ID";
final String LOAD_BY_NIX = "SELECT * FROM Buecher";
try {
//DRIVER LOAD
Class.forName("com.mysql.jdbc.Driver");
//Connect to DB
con = DriverManager.getConnection("jdbc:mysql://x/x", "x", "x");
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "
+ "Transitional//EN\">\n";
if (request.getParameter("action") != null) {
String authorPara = request.getParameter("author");
String buchPara = request.getParameter("titel");
String schlagwortPara = request.getParameter("schlagwort");
String sqlStmt;
if (authorPara != null && authorPara.length() > 0 && buchPara != null
&& buchPara.length() > 0 && schlagwortPara != null
&& schlagwortPara.length() > 0) {
pstmt = con.prepareStatement(LOAD_BY_ALL);
pstmt.setString(1, "%" + authorPara + "%");
pstmt.setString(2, "%" + buchPara + "%");
pstmt.setString(3, "%" + schlagwortPara + "%");
}
else if (authorPara != null && authorPara.length() > 0) {
pstmt = con.prepareStatement(LOAD_BY_AUTHOR);
pstmt.setString(1, "%" + authorPara + "%");
}
else if (buchPara != null && buchPara.length() > 0) {
pstmt = con.prepareStatement(LOAD_BY_TITEL);
pstmt.setString(1, "%" + buchPara + "%");
}
else if (schlagwortPara != null && schlagwortPara.length() > 0) {
pstmt = con.prepareStatement(LOAD_BY_SCHLAGWORT);
pstmt.setString(1, "%" + schlagwortPara + "%");
}
else {
pstmt = con.prepareStatement(LOAD_BY_NIX);
}
rst = pstmt.executeQuery();
//______________________________
out.println(docType
+ "<HTML>\n"
+ "<BODY bgcolor=\"AZURE\">
+ "<title>Suchergebnis</title>
+ "<center>"
+ "<h4>Zu Ihrer Suchanfrage konnten folgende Bücher gefunden werden</h4>"
+ "<div>"
+ "<table border=\"3\" cellspacing=\"0\" cellpadding=\"0\" "
+ "bgcolor=\"WHITE\"style=\"width: 70%; height: 10%;\" align=\"center\">\n"
+ "<tr bgcolor=\"POWDERBLUE\">" + "<td>"
+ "<center>[b]Nr.[/b]</center>" + "</td>" + "<td>"
+ "<center>[b]Titel[/b]</center>" + "</td>" + "<td>"
+ "<center>[b]Author[/b]</center>" + "</td>" + "</tr>" + "<tr>"
+ "<td>" + "<center>" + rst.getString("Titel") + "</center>\n"
+ "</td>" + "<td>" + "<center>" + rst.getString("Author")
+ "</center>\n" + "</td>" + "</tr>" + "</table>" + "</center>"
+ "</BODY>" + "</HTML>");
con.close();
rst.close();
pstmt.close();
}
else {
out.println(docType + "<HTML>\n" + "<head>"
+ "<script>+function validate(objForm) {"
+ "if (objForm.authorPara.value.length == 0) {"
+ "objForm.authorPara.focus();" + "}"
+ "if (objForm.buchPara.value.length == 0) {" + "objForm.buchPara.focus();"
+ "}" + "if (objForm.schlagwortPara.value.length == 0) {"
+ "objForm.schlagwort.focus();" + "}" + "return true;" + "</script>"
+ "<TITLE>Search</TITLE>\n"
+ "</head>" + "</HTML>"
+ "<BODY BGCOLOR=\"LIGHTSTEELBLUE\">"
+"<center>\n"
+ "<form action=\"VerbindungBS.java\" method=\"post\" name=\"entry\" "
+ "onSubmit=\"return validate(this)\"><input type=\"hidden\"value=\"list\" name=\"action\">\n"
+ "<table>\n"
+ "<tr>\n"
+ "<td>\n"
+ "<table bgcolor=\"POWDERBLUE\">"
+ "<tr>\n"
+ "<td colspan=\"2\" align=\"center\">"
+ "<h2><blink>Bibliothek</blink></h2>\n"
+ "</td>\n"
+ "</tr>\n"
+ "<tr>"
+ "<td colspan=\"2\">&</td>\n"
+ "</tr>"
+ "<tr>"
+ "<td>Buchtitel:</td>\n"
+ "<td><input name=\"titel\" type=\"text\" size=\"50\"></td>\n"
+ "</tr>"
+ "<tr>"
+ "<td>Author:</td>\n"
+ "<td><input name=\"author\" type=\"text\" size=\"50\"></td>\n"
+ "</tr>"
+ "<tr>"
+ "<td>Schlagwort:</td>\n"
+ "<td><input name=\"schlagwort\" type=\"text\" size=\"50\"></td>\n"
+ "</tr>"
+ "<tr>"
+ "<td colspan=\"2\" align=\"center\"><input type=\"submit\"value=\"..::: s u c h e n :::..\" size=\"30\"></td>\n"
+ "</tr>" + "</td>" + "</tr>" + "</form>" + "</center>" + "</BODY>"
+ "</HTML>");
out.flush();
out.close();
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}