在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 应用服务器中。
为了将输出发送到客户端,您必须创建一个输出的通道和 getWriter() 方法,以便 response 对象能够提供您所需要的对象。它与系统级的 System.out 输出对象的工作方式非常类似。
与基于命令行的问卷调查相同,在输出了主要的页面元素之后,您必须遍历问卷调查集合以输出每个 HTML 组件。您需要在您的问卷调查类中创建一个新的方法 askhtml(),以输出 HTML 信息。您还需要提供 response 的输出流对象和唯一的 ID。
您可以在清单 11 中看到 doGet 的基本代码。
清单 11. WebSurvey 类 doGet() 方法源代码public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
Integer formfieldid = 1;
response.setContentType("text/html");
out.println("<h1>Survey</h1>");
out.println("<form action="/WebSurvey/survey" method="POST">");
for(Iterator<SurveyQuestion> i = survey.iterator(); i.hasNext(); ) {
SurveyQuestion question = (SurveyQuestion) i.next();
question.askhtml(formfieldid,out);
formfieldid++;
}
out.println("<input type="hidden" name="highfieldid" value=""
+ survey.size() + "">");
out.println("<input type="submit">");
out.println("</form>");
}
来源:ibm 作者:Martin Brown 责编:豆豆技术应用