alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  
"); writer.println( "<TR>"); writer.println( "</tr>

Apache CXF example source code file (DemoServletBase.java)

This example Apache CXF source code file (DemoServletBase.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 - Apache CXF tags/keywords

demos, demoservletbase, demoservletbase, exception, http, httpservlet, httpservletresponse, io, j2ee, printwriter, printwriter, request, response, servlet, string, string, tr, tr

The Apache CXF DemoServletBase.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package demo.servlet;

import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/** Abstract base class for demo servlets.  Provides a consistent
 *  look&feel for the servlet based demos. Subclasses are only
 *  required to display the portions of the page relevant to their
 *  demo, minimizing the amount of clutter in the demo code.
 *
 * The servlet is based on the template method pattern. Subclasses
 * are required to implement the <code>writeMainBody method.
 * the basic structure of the page is already laid out when this
 * method is invoke so there is no need to for <body> or
 * <head> type tags.
 */ 
public abstract class DemoServletBase extends HttpServlet {

    final String pageTitle; 

    public DemoServletBase(String pageTitle) {
    
        this.pageTitle = pageTitle; 
    }
  


    public void  doGet(HttpServletRequest req, HttpServletResponse resp) { 

        PrintWriter writer = null; 
    
        try { 

            resp.setContentType("text/html");
            writer = resp.getWriter();  
            writer.println("<html>"); 

            // write out the page header
            
            writeHeader(writer);

            // write out the body including displaying 
            
            writeBody(writer); 

      
            writer.println("</html>"); 
      
            writer.close(); 

        } catch (Exception ex) { 
            ex.printStackTrace(); 

        } finally { 
            if (writer != null) { 
                writer.close(); 
            } 
      
        } 
    
    } 


    protected void writeBody(PrintWriter writer) { 
    
        writer.println("<body  topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" margins=\"0\">"); 
        writePageHeader(writer); 
    
    
        writer.println("<h2>
  " + pageTitle + ""); writeMainBody(writer); writer.println("</td>"); writer.println("</tr>"); writer.println("</table>"); writer.println("</body>"); writer.println("</html>"); writer.close(); } protected void writePageHeader(PrintWriter writer) { writer.println( "<table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" + "<TR>
" + "<img src=\"images/spacer.gif\" width=\"2\">" + "</td>" + "<img src=\"images/cxf_banner.gif\" width=\"350\" height=\"57\">
" + "</td>" + "</td>
" + "</td>" + "</td>"); } protected void writeHeader(PrintWriter writer) { writer.println("<head>"); writer.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"./cxf_doc.css\"/>"); writer.println("<title>CXF J2EE Demos"); writer.println("</head>"); } protected abstract void writeMainBody(PrintWriter writer); }

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF DemoServletBase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

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.