Pack200, Applets and Java Plug-in

The following URL covers using pack200 compression in Java 1.5: 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()

   1  /** Called when someone accesses the servlet. */
   2     public void doGet(HttpServletRequest request, 
   3                 HttpServletResponse response) 
   4                 throws IOException, ServletException {
   5         
   6         String encoding = request.getHeader(ACCEPT_ENCODING);
   7         String pathInfo = request.getPathInfo();
   8         String pathInfoEx = request.getPathTranslated();
   9         String contentType = request.getContentType();
  10         String contextPath = request.getContextPath();
  11         String requestURL  = request.getRequestURL().toString();
  12         String requestName = pathInfo; 
  13         
  14         ServletContext sc = getServletContext();
  15         String realPath = sc.getRealPath("");
  16         sc.log("----------------------------");
  17         sc.log("pathInfo="+pathInfo);
  18         sc.log("pathInfoEx="+pathInfoEx);
  19         sc.log("Accept-Encoding="+encoding);
  20         sc.log("Content-Type="+contentType);
  21         sc.log("contextPath="+contextPath);
  22         sc.log("realPath="+realPath);
  23         sc.log("requestURL="+requestURL);
  24 
  25         try
  26         {
  27             URL url = new URL(requestURL);
  28             sc.log("url file="+url.getFile());
  29             if (pathInfoEx == null) {
  30                 int ndx = realPath.indexOf(contextPath);
  31                 if (ndx > 0)
  32                 {
  33                     String file = url.getFile();
  34                     String path = realPath.substring(0, ndx)+file;
  35                     sc.log("path="+path);
  36                     pathInfoEx = path;
  37                     ndx = file.indexOf(contextPath);
  38                     if (ndx == 0)
  39                     {
  40                         pathInfo = file.substring(contextPath.length());
  41                         sc.log("new pathInfo="+pathInfo);
  42                     }
  43                 }
  44             }
  45         }
  46         catch (Exception ex) { sc.log("url "+ex); }
  47         
  48         if (pathInfoEx == null) {
  49             sc.log("----------NOT FOUND---------");
  50             response.sendError(response.SC_NOT_FOUND);
  51             return;
  52         }
  53         String outFile = pathInfo;
  54         ...

Pack200 (last edited 2012-06-22 14:09:41 by drool)