I want in the code below when i click the button submit. The values in all the html input to be submitted into another Servlet request parameter.
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/DefaultDB");
Connection conn = ds.getConnection();
PreparedStatement ps1 = conn.prepareStatement(
"select t1.EMPLOYEEID, t1.NAME, t1.BIRTHDATE, t2.TEMPID, t2.Sender, t2.EmailSubject, t2.EmailContent from Employee t1 Left join (select * from Template_Employee a,Template b where a.EventType = ? And a.templateId = b.TEMPID) t2 on t1.EMPLOYEEID= t2.EmployeeId where t1.BIRTHDATE BETWEEN ? AND ?");
ps1.setString(1, "Birthday");
ps1.setString(2, sdf.format(fromDate));
ps1.setString(3, sdf.format(toDate));
ResultSet rs = ps1.executeQuery();
st = rs.next();
if (!st) {
response.getWriter().println("No Employee in the specified dates");
}
while (st) {
list.add(rs.getInt(1));
list.add(rs.getString(2));
list.add(rs.getObject(3));
list.add("Birthday");
list.add(rs.getInt(4));
list.add(rs.getString(5));
list.add(rs.getString(6));
list.add(rs.getString(7));
st = rs.next();
}
response.getWriter().println(list.toString());
} catch (Exception e) {
response.getWriter().println(e.toString());
}
response.getWriter().println("<p><table border=\"1\"><tr><th colspan=\"3\">" + list.size() / 8
+ " entries in the Database</th></ tr>"
+ (list.isEmpty() ? "<tr><td colspan=\"3\">Database is empty</td></tr>"
: "<tr><th>EmployeeId</th><th>Employee Name</th><th>Event Date</th><th>Event Type</th><th>TemplateId</th><th>Sender</th><th>Email Subject</th><th>Email Body</th></ tr>"));
for (int i = 0; list.size() > i; i += 8) {
response.getWriter().println("<tr><td>" + list.get(i) + "</td><td>" + list.get(i + 1) + "</td><td>"
+ list.get(i + 2) + "</td><td>" + list.get(i + 3) + "</td>"
+ ((int) list.get(i + 4) == 0
? "<td> <input type=\"number\" name=\"tempId\" /></td>" + "<td>"
+ "Please Choose a templateId" + "</td><td>" + "Please Choose a templateId"
+ "</td><td>" + "Please Choose a templateId" + "</td></ tr>"
: "<td>" + list.get(i + 4)
+ "</td>" + "<td>" + list.get(i + 5) + "</td><td>" + list.get(i + 6)
+ "</td><td>" + list.get(i + 7) + "</td></ tr>"
)
);
}
response.getWriter().println("<input type=\"submit\" value=\"Submit\" />");
response.getWriter().println("</table></p>");
} catch (Exception e) {
}
}
So this is what i see when running this code Program Output
So i need to know how can i create another servlet that takes the values of the templateId text field input As a parameter in this other servlet. So i need to use those numbers to enter them in the database of templates.
ThankYou All :)
Aucun commentaire:
Enregistrer un commentaire