home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java EE 6 example source code file (OmissionServlet.java)

This example Java EE 6 source code file (OmissionServlet.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Java EE 6 tags/keywords

http, httpservlet, httpservletresponse, httpservletresponse, io, ioexception, ioexception, omissionservlet, principal, printwriter, printwriter, request, response, security, servlet, servletexception, servletexception, string, welcome

The Java EE 6 OmissionServlet.java source code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enterprise.http_method_omission;

import java.io.*;

import java.security.Principal;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author nithyasubramanian
 */
public class OmissionServlet extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET and POST methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Principal userPrincipal = request.getUserPrincipal();
        String userName = userPrincipal.getName();

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            // TODO output your page here
            out.println("<html>");
            out.println("<body>");
            out.println("Welcome " + userName);
            out.println("</body>");
            out.println("</html>");

        } finally {
            out.close();
        }

    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }
}

Other Java EE 6 examples (source code examples)

Here is a short list of links related to this Java EE 6 OmissionServlet.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.