建立一个 Derby 日历,第 2 部分: 嵌入选项(下)
2010-04-19 00:00:00 来源:WEB开发网图 8. 登录响应
创建新的事件
登录页面完成了原来的 GUI 提示的工作,即提供用户名和口令。建立登录页面后,可以添加新的事件。创建一个新的 servlet 类 MainFrame,并添加一个简单的 HTML 表单,如 清单 23 所示。
清单 23. 创建新的事件
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import javax.servlet.http.Cookie;
public final class MainFrame extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String username = null;
String password = null;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>The calendar system</title>");
out.println("</head><body>");
out.println("<table width='100%'><tr><td valign='top'>");
leftSide(request, response, username, password);
out.println("</td><td valign='top'>");
rightSide(request, response, username, password);
out.println("</td></tr></table>");
out.println("</body></html>");
}
private void leftSide(HttpServletRequest request,
HttpServletResponse response,
String username, String password)
throws IOException {
PrintWriter out = response.getWriter();
out.println("<form action='calendar' method='post'>");
out.println("<h2>Enter a new event</h2>");
out.println("<table>");
out.println("<tr><td>Date:</td><td>");
out.println("<select name='month'>");
out.println("<option value='1'>January</option>");
out.println("<option value='2'>February</option>");
out.println("<option value='3'>March</option>");
out.println("<option value='4'>April</option>");
out.println("<option value='5'>May</option>");
out.println("<option value='6'>June</option>");
out.println("<option value='7'>July</option>");
out.println("<option value='8'>August</option>");
out.println("<option value='9'>September</option>");
out.println("<option value='10'>October</option>");
out.println("<option value='11'>November</option>");
out.println("<option value='12'>December</option>");
out.println("</select>");
out.println("/");
out.println("<select name='day'>");
for (int i=1; i<32; i++){
out.println("<option value='"+i+"'>"+i+"</option>");
}
out.println("</select>");
out.println("/");
out.println("<select name='year'>");
for (int i=2005; i < 2010; i++){
out.println("<option value='"+i+"'>"+i+"</option>");
}
out.println("</select>");
out.println("</td></tr>");
out.println("<tr><td>Title:</td><td>");
out.println("<input type='text' name='title' />");
out.println("</td></tr>");
out.println("<tr><td>Description:</td><td>");
out.println("<textarea rows='5' cols='30' name='description'></textarea>");
out.println("</td></tr>");
out.println("<tr><td>Reminders to:</td><td>");
out.println("<input type='text' name='remindersTo' />");
out.println("</td></tr><tr><td>");
out.println("<input type='submit' value='Submit' />");
out.println("</td></tr></table>");
out.println("</form>");
}
private void rightSide(HttpServletRequest request,
HttpServletResponse response,
String username, String password)
throws IOException {
}
}
更多精彩
赞助商链接