Platinum Partner

Simple Java Servlet

// Simple Servlet Skeleton


package net.tvs.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MyServlet extends HttpServlet
{
  private static Log _logger = LogFactory.getLog( MyServlet.class );

  public void init(ServletConfig config) throws ServletException
  {
    super.init( config );
    try
      {
        // Initialization
      }
    catch ( Exception e )
      {
        _logger.fatal( e.getMessage() );
      }
    _logger.info( "MyServlet initialized" );
  }
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
  {
    processRequest( request, response );
  }

  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
  {
    processRequest( request, response );
  }

  protected void processRequest(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException
  {
    response.setContentType( "text/html;charset=UTF-8" );
    String param = request.getParameter( "param" );
    _logger.debug( "Received param: " + param );

    // Implementation...

    PrintWriter out = response.getWriter();
    response.setContentType( "text/xml" );
    response.setHeader( "Cache-Control", "no-cache" );

    out.println( "" );
    out.println( "" + param + "" );
    out.println( "" );
    out.close();
  }

}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}