Pack200

Pack200, Applets and Java Plug-in

The following URL covers using pack200 compression in Java 1.5: [WWW] http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html.

However, the sample servlet from that page had to be modified for use with the Java Plug-in.

Revised partial doGet()

 /** Called when someone accesses the servlet. */
    public void doGet(HttpServletRequest request, 
                HttpServletResponse response) 
                throws IOException, ServletException {
        
        String encoding = request.getHeader(ACCEPT_ENCODING);
        String pathInfo = request.getPathInfo();
        String pathInfoEx = request.getPathTranslated();
        String contentType = request.getContentType();
        String contextPath = request.getContextPath();
        String requestURL  = request.getRequestURL().toString();
        String requestName = pathInfo; 
        
        ServletContext sc = getServletContext();
        String realPath = sc.getRealPath("");
        sc.log("----------------------------");
        sc.log("pathInfo="+pathInfo);
        sc.log("pathInfoEx="+pathInfoEx);
        sc.log("Accept-Encoding="+encoding);
        sc.log("Content-Type="+contentType);
        sc.log("contextPath="+contextPath);
        sc.log("realPath="+realPath);
        sc.log("requestURL="+requestURL);

        try
        {
            URL url = new URL(requestURL);
            sc.log("url file="+url.getFile());
            if (pathInfoEx == null) {
                int ndx = realPath.indexOf(contextPath);
                if (ndx > 0)
                {
                    String file = url.getFile();
                    String path = realPath.substring(0, ndx)+file;
                    sc.log("path="+path);
                    pathInfoEx = path;
                    ndx = file.indexOf(contextPath);
                    if (ndx == 0)
                    {
                        pathInfo = file.substring(contextPath.length());
                        sc.log("new pathInfo="+pathInfo);
                    }
                }
            }
        }
        catch (Exception ex) { sc.log("url "+ex); }
        
        if (pathInfoEx == null) {
            sc.log("----------NOT FOUND---------");
            response.sendError(response.SC_NOT_FOUND);
            return;
        }
        String outFile = pathInfo;
        ...

last edited 2005-07-05 22:09:32 by StanDickerson