Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.servlet;
 
 
 
 
 
 /* ------------------------------------------------------------ */
Servlet handling JSP Property Group mappings

This servlet is mapped to by any URL pattern for a JSP property group. Resources handled by this servlet that are not directories will be passed directly to the JSP servlet. Resources that are directories will be passed directly to the default servlet.

 
 public class JspPropertyGroupServlet extends GenericServlet
 {
     private static final long serialVersionUID = 3681783214726776945L;
     
     public final static String NAME = "__org.eclipse.jetty.servlet.JspPropertyGroupServlet__";
     private final ServletHandler _servletHandler;
     private final ContextHandler _contextHandler;
     private ServletHolder _dftServlet;
     private ServletHolder _jspServlet;
     private boolean _starJspMapped;
     
     public JspPropertyGroupServlet(ContextHandler contextServletHandler servletHandler)
     {
         =context;
         =servletHandler;        
     }
     
     @Override
     public void init() throws ServletException
     {            
         String jsp_name = "jsp";
         ServletMapping servlet_mapping =.getServletMapping("*.jsp");
         if (servlet_mapping!=null)
         {
             =true;
            
             //now find the jsp servlet, ignoring the mapping that is for ourself
             ServletMapping[] mappings = .getServletMappings();
             for (ServletMapping m:mappings)
             {
                 String[] paths = m.getPathSpecs();
                 if (paths!=null)
                 {
                     for (String path:paths)
                     {
                         if ("*.jsp".equals(path) && !.equals(m.getServletName()))
                             servlet_mapping = m;
                     }
                 }
             }
             
             jsp_name=servlet_mapping.getServletName();
         }
         =.getServlet(jsp_name);
         
         String dft_name="default";
         ServletMapping default_mapping=.getServletMapping("/");
         if (default_mapping!=null)
             dft_name=default_mapping.getServletName();
         =.getServlet(dft_name);
     }
 
     @Override
     public void service(ServletRequest reqServletResponse resthrows ServletExceptionIOException
     {           
         Request request=(req instanceof Request)?(Request)req:AbstractHttpConnection.getCurrentConnection().getRequest();
        String servletPath=null;
        String pathInfo=null;
        if (request.getAttribute(.)!=null)
        {
            servletPath=(String)request.getAttribute(.);
            pathInfo=(String)request.getAttribute(.);
            if (servletPath==null)
            {
                servletPath=request.getServletPath();
                pathInfo=request.getPathInfo();
            }
        }
        else
        {
            servletPath = request.getServletPath();
            pathInfo = request.getPathInfo();
        }
        
        String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
        
        if (pathInContext.endsWith("/"))
        {
            .getServlet().service(req,res);
        }
        else if ( && pathInContext.toLowerCase().endsWith(".jsp"))
        {
            .getServlet().service(req,res);
        }
        else
        {
         
            Resource resource = .getResource(pathInContext);
            if (resource!=null && resource.isDirectory())
                .getServlet().service(req,res);
            else
                .getServlet().service(req,res);
        }
        
    }
New to GrepCode? Check out our FAQ X