JAVA Servlet2.3外文书籍源码

源代码在线查看: topics.java

软件大小: 458 K
上传用户: haowoainime
关键词: Servlet JAVA 2.3 书籍
下载地址: 免注册下载 普通下载 VIP

相关代码

				package forum;
				
				import java.util.*;
				
				/**
				 * Represents all topics in the discussion forum.
				 * 
				 * In a real system there would be a database containing the topics.
				 *
				 * @author    Simon Brown
				 */
				public class Topics {
				
				  /** a collection of all topics in the system */
				  private static ArrayList topics = new ArrayList();
				
				  /**
				   * Populates the collection of all topics when the class is loaded.
				   */
				  static {
				    Topic topic;
				    Response response;
				    User user1, user2;
				
				    user1 = Users.getUser("Simon");
				    user2 = Users.getUser("Sam");
				
				    topic = new Topic(0, user1, "How do I write a Java Servlet?", "How do I write a Java Servlet and which class do I need to extend?");
				    topic.add(new Response(user2, "You need to write a Java class that extends javax.servlet.http.HttpServlet, and implement the doGet or doPost methods."));
				    topic.add(new Response(user1, "What's the purpose of doGet and doPost?"));
				    topics.add(topic);
				
				    topic = new Topic(1, user1, "Front Controller pattern?", "How do I use it?");
				    topics.add(topic);
				
				    topic = new Topic(2, user1, "HTTP session timeout", "When does the session timeout?");
				    topics.add(topic);
				  }
				
				  /**
				   * Gets a collection of all topics in the system.
				   *
				   * @return  a Collection of Topic instances
				   */
				  public static Collection getTopics() {
				    return topics;
				  }
				
				  /**
				   * Looks up the Topic with the specified id.
				   *
				   * @param id    the topic id
				   * @return  the appropriate Topic instance
				   */
				  public static Topic getTopic(int id) {
				    return (Topic)topics.get(id);
				  }
				
				}			

相关资源