Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

TestServletServlet.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2005 Modification Romain Beaugrand
00027  * 
00028  */
00029 
00030 package org.openmobileis.embedded.webserver.test.services.servlet;
00031 
00032 import java.io.IOException;
00033 import java.io.PrintWriter;
00034 import java.util.Enumeration;
00035 
00036 import javax.servlet.ServletException;
00037 import javax.servlet.http.HttpServlet;
00038 import javax.servlet.http.HttpServletRequest;
00039 import javax.servlet.http.HttpServletResponse;
00040 
00046 public class TestServletServlet extends HttpServlet {
00047   static final long serialVersionUID = 5521257935120563452L;
00048  
00049     /*
00050      * Start service from GET method, same behavior as POST @param req the
00051      * servlet request @param req the servlet response @exception
00052      * ServletException when an exception has occurred
00053      */
00054     
00055     public TestServletServlet() {
00056     }
00057     
00058     public void init() throws ServletException {
00059     }
00060     
00061     public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00062         this.processRequest(req, res);
00063     }
00064 
00075     public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00076         this.processRequest(req, res);
00077     }
00078 
00079     private void processRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00080         res.setContentType("text/html");
00081         
00082         StringBuffer sb = new StringBuffer(200);
00083 /*        sb.append("<HTML>\n").append("<HEAD><TITLE>Test Servlet</TITLE></HEAD>\n")
00084                         .append("<BODY>\n").append("ServletName : "+this.getServletName())
00085                         .append("\n</BODY></HTML>\n\0");*/
00086         sb.append("<HTML>\n").append("<HEAD><TITLE>Test Servlet</TITLE></HEAD>\n")
00087                 .append("<BODY>\n")
00088                 .append("ServletInfo : "+this.getServletInfo())
00089                 .append("\n<br>\nServletName : "+this.getServletName())
00090                 .append("\n<br>\nMajor version : "+this.getServletContext().getMajorVersion())
00091                 .append("\n<br>\nMinor version : "+this.getServletContext().getMinorVersion())
00092         .append("\n<br>\nInit Parameters");
00093         
00094         Enumeration enuma = this.getInitParameterNames();
00095         while (enuma.hasMoreElements()) {
00096             String parameterName = (String)enuma.nextElement();
00097             String parameterValue = this.getInitParameter(parameterName);
00098             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Name : "+parameterName);
00099             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Value : "+parameterValue);
00100         }
00101         
00102         sb.append("\n<br>\nAttributes");
00103         enuma = this.getServletContext().getAttributeNames();
00104         while (enuma.hasMoreElements()) {
00105             String attributeName = (String)enuma.nextElement();
00106             String attributeValue = this.getInitParameter(attributeName);
00107             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Name : "+attributeName);
00108             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Value : "+attributeValue);
00109         }
00110         
00111                 sb.append("\n<br>\nServer info : "+this.getServletContext().getServerInfo())
00112                 .append("\n<br>\nServletContextName : "+this.getServletContext().getServletContextName())
00113                 .append("\n</BODY></HTML>\n");
00114         //res.setContentLength(sb.length());
00115         
00116         PrintWriter out = res.getWriter();
00117         //ServletOutputStream out = res.getOutputStream();
00118         
00119         out.print(sb.toString());
00120     }
00121 
00122 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4