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 * PingServlet2Servlet is the initial servlet that sends a request to {@link PingServlet2ServletRcv} 034 * 035 */ 036 public class PingServlet2Servlet extends HttpServlet { 037 private static int hitCount = 0; 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 * this is the main method of the servlet that will service all get requests. 051 * @param request HttpServletRequest 052 * @param responce HttpServletResponce 053 **/ 054 public void doGet(HttpServletRequest req, HttpServletResponse res) 055 throws ServletException, IOException { 056 PingBean ab; 057 try 058 { 059 ab = new PingBean(); 060 hitCount++; 061 ab.setMsg("Hit Count: " + hitCount); 062 req.setAttribute("ab", ab); 063 064 getServletConfig().getServletContext().getRequestDispatcher("/servlet/PingServlet2ServletRcv").forward(req, res); 065 } 066 catch (Exception ex) 067 { 068 Log.error( 069 ex, "PingServlet2Servlet.doGet(...): general exception"); 070 res.sendError(500, "PingServlet2Servlet.doGet(...): general exception" + ex.toString()); 071 072 } 073 } 074 }