001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.samples.daytrader.web.prims; 018 019 import java.io.*; 020 import javax.servlet.*; 021 import javax.servlet.http.*; 022 023 import org.apache.geronimo.samples.daytrader.util.*; 024 025 026 /** 027 * 028 * PingServlet2Servlet tests servlet to servlet request dispatching. Servlet 1, 029 * the controller, creates a new JavaBean object forwards the servlet request with 030 * the JavaBean added to Servlet 2. Servlet 2 obtains access to the JavaBean through 031 * the Servlet request object and provides the dynamic HTML output based on the JavaBean 032 * data. 033 * PingServlet2ServletRcv receives a request from {@link PingServlet2Servlet} and displays output. 034 * 035 */ 036 public class PingServlet2ServletRcv extends HttpServlet { 037 private static String initTime = null; 038 039 /** 040 * forwards post requests to the doGet method 041 * Creation date: (11/6/2000 10:52:39 AM) 042 * @param res javax.servlet.http.HttpServletRequest 043 * @param res2 javax.servlet.http.HttpServletResponse 044 */ 045 public void doPost(HttpServletRequest req, HttpServletResponse res) 046 throws ServletException, IOException { 047 doGet(req, res); 048 } 049 050 051 /** 052 * this is the main method of the servlet that will service all get requests. 053 * @param request HttpServletRequest 054 * @param responce HttpServletResponce 055 **/ 056 public void doGet(HttpServletRequest req, HttpServletResponse res) 057 throws ServletException, IOException { 058 PingBean ab; 059 try 060 { 061 ab = (PingBean) req.getAttribute("ab"); 062 res.setContentType("text/html"); 063 PrintWriter out = res.getWriter(); 064 out.println( 065 "<html><head><title>Ping Servlet2Servlet</title></head>" 066 + "<body><HR><BR><FONT size=\"+2\" color=\"#000066\">PingServlet2Servlet:<BR></FONT><FONT size=\"+1\" color=\"#000066\">Init time: " 067 + initTime 068 + "</FONT><BR><BR><B>Message from Servlet: </B>" 069 + ab.getMsg() 070 + "</body></html>"); 071 } 072 catch (Exception ex) 073 { 074 Log.error(ex, "PingServlet2ServletRcv.doGet(...): general exception"); 075 res.sendError( 076 500, 077 "PingServlet2ServletRcv.doGet(...): general exception" 078 + ex.toString()); 079 } 080 081 } 082 /** 083 * called when the class is loaded to initialize the servlet 084 * @param config ServletConfig: 085 **/ 086 public void init(ServletConfig config) throws ServletException { 087 super.init(config); 088 initTime = new java.util.Date().toString(); 089 090 } 091 }