servlet协作

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		getServletContext().setAttribute("Hello",new Date());
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		Date now = (Date)getServletContext().getContext("/BindSession/servlet/Setter").getAttribute("Hello"); 
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		out.println(now);
		out.flush();
		out.close();
	}

Getter通过一个类似钩子的东西,获得了另外一个servlet的ServletContext。用来共享信息但需要全路经uri不可以用相对路径

你可能感兴趣的:(java,servlet)