在AIX Version 5.3中使用Java和PHP技术进行开发(2)

http://tech.ddvip.com   2008年11月13日    社区交流

本教程创建了一个简单的 Java 业务应用程序,然后将其作为 Servlet 部署到运行 IBM AIX® Version 5.3 操作系统的 System p™ 系统的 Apache Tomcat 应用服务器中。

  现在,当您为每个 SurveyQuestion 对象调用 askhtml() 时,将生成一个合适的表单字段。

  为了解析表单,您需要为 Servlet 定义 doPost() 方法。

  doPost() 方法

  为了处理来自表单的输入数据,Web 应用服务器将调用 doPost() 方法。

  对于您的问卷调查应用程序,这意味着输出每个问题,然后读取每个表单字段响应,并输出结果。因为您采用了与生成该表单时相同的遍历方式来遍历这些问题,所以您可以使用相同的方法为每个表单元素生成一个唯一的 ID 并访问其内容。

  清单 14 中显示了用于该目的的代码。

  清单 14. WebSurvey 类 doPost() 方法源代码public void doPost(HttpServletRequest request,
          HttpServletResponse response)
  throws ServletException, IOException {
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  out.println("<h1>Results</h1>");
  Integer fieldid = 1;
  for(Iterator<SurveyQuestion> i = this.survey.iterator();
    i.hasNext(); ) {
    SurveyQuestion question = (SurveyQuestion) i.next();
    question.showquestion(out,false);
    out.println("<p>" +
          request.getParameter("field" +
          fieldid));
    fieldid++;
  }
}

  在编写了 Servlet 应用程序和核心类的扩展之后,您需要对 Servlet 进行编译,然后将其部署到 Tomcat 应用服务器中。

来源:ibm    作者:Martin Brown    责编:豆豆技术应用

正在加载评论...