?
Solved

Why is it not working ?

Posted on 2003-02-25
6
Medium Priority
?
215 Views
Last Modified: 2013-11-24
Hi,
 Here's the result (below), but where's the (picture/gifs) ?


My Local Host -(Http://Local/servlet/coreservlets.PersistentConnection)

/servlet/coreservlets/bullets/b01lis.gif  /servlet/coreservlets/bullets/b02lis.gif  /servlet/coreservlets/bullets/b03lis.gif  /servlet/coreservlets/bullets/b04lis.gif  /servlet/coreservlets/bullets/b05lis.gif  /servlet/coreservlets/bullets/b06lis.gif  /servlet/coreservlets/bullets/b07lis.gif  /servlet/coreservlets/bullets/b08lis.gif  /servlet/coreservlets/bullets/b09lis.gif  /servlet/coreservlets/bullets/b010lis.gif  /servlet/coreservlets/bullets/b011lis.gif  /servlet/coreservlets/bullets/b012lis.gif  /servlet/coreservlets/bullets/b013lis.gif  /servlet/coreservlets/bullets/b014lis.gif  /servlet/coreservlets/bullets/b015lis.gif  /servlet/coreservlets/bullets/b016lis.gif  /servlet/coreservlets/bullets/b017lis.gif  /servlet/coreservlets/bullets/b018lis.gif  /servlet/coreservlets/bullets/b019lis.gif  /servlet/coreservlets/bullets/b020lis.gif  /servlet/coreservlets/bullets/b021lis.gif  /servlet/coreservlets/bullets/b022lis.gif  /servlet/coreservlets/bullets/b023lis.gif  /servlet/coreservlets/bullets/b024lis.gif  /servlet/coreservlets/bullets/b025lis.gif  /servlet/coreservlets/bullets/b026lis.gif  /servlet/coreservlets/bullets/b027lis.gif  /servlet/coreservlets/bullets/b028lis.gif  /servlet/coreservlets/bullets/b029lis.gif


And here's the codes..



[PersistentConnection.java]
package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

/** Illustrates the value of persistent HTTP Connections for
*   pages that include many images, applet classes, or
*   other auxiliary content that would otherwise require
*   a separate connection to retrieve.
*/

public class PersistentConnection extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
     response.setContentType("text/html");
     ByteArrayOutputStream byteStream = new ByteArrayOutputStream(7000);
      PrintWriter out = new PrintWriter(byteStream,true);
      String persistenceFlag = request.getParameter("usePersistence");
       boolean usePersistence = ((persistenceFlag == null) ||
                                (!persistenceFlag.equals("no")));
       String title;
       if (usePersistence) {
         title = "PRUWeb is Using Persistent Connection";
         } else {
         title = "PRUWeb Not Using Persistent Connection";
         }

         out.println(ServletUtilities.headWithTitle(title) +
            "<BODY BGCOLOR=\"#FDF5E6\">\n" +
            "<H1 ALIGN=\"CENTER\">" + title + "</H1>");
         int numImages = 30;

         int n = 1;
//       String le = "/servlet/coreservlets.ImageRetriever?gifLocation=" +
//                   "servlet/coreservlets/bullet/b0" + n + "lis.gif";

         String le = "/servlet/coreservlets/bullets/b0" + n + "lis.gif";


         for(int i=1; i<numImages; i++) {
           out.println(makeImage(i, usePersistence));
//           le = "/servlet/coreservlets.ImageRetriever?gifLocation=" +
//                "servlet/coreservlets/bullets/b0" + i + "lis.gif";
           le = "/servlet/coreservlets/bullets/b0" + i + "lis.gif";


           out.println(le);
           
         }

         out.println("</BODY></HTML>");
         if (usePersistence) {
           response.setContentLength(byteStream.size());
         }
           byteStream.writeTo(response.getOutputStream());
        }

        private String makeImage(int n, boolean usePersistence) {
           String file = "/servlet/coreservlets.ImageRetriever?gifLocation=" +
                       "/bullets/b0" + n + "lis.gif";        

//      String file = "/servlet/coreservlets/bullets/b0" + n + "lis.gif";        


         if (!usePersistence)
            file = file + "&usePersistence=no";
            return("<IMG SRC=\"" + file + "\"\n" +
                   "     WIDTH=6 HEIGHT=6 ALT=\"\">");          

        }

        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
                doGet(request, response);
        }
       }




[ImageRetriever.java]

package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/** A servlet that reads a GIF file off the local system and sends it to
*   the client with the appropriate MIME type. Includes the Content-Length
*   header to support the use of persistent HTTP connections unless explicitly
*   instructed not to through "usePersistence=no".
*   Used by the PersistentConnection servlet.
*/

public class ImageRetriever extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  String gifLocation = request.getParameter("gifLocation");
  if ((gifLocation == null) ||
      (gifLocation.length() == 0)) {
     reportError(response, "Image File Not Specified");
     return;
  }

  String file = getServletContext().getRealPath(gifLocation);
  try {
        BufferedInputStream in =
           new BufferedInputStream(new FileInputStream(file));
           ByteArrayOutputStream byteStream = new ByteArrayOutputStream(512);
        int imageByte;

        while((imageByte = in.read()) != -1) {
               byteStream.write(imageByte);
        }

        in.close();
        String persistenceFlag = request.getParameter("usePersistence");
        boolean usePersistence = (( persistenceFlag == null) ||
                                  (!persistenceFlag.equals("no")));
        response.setContentType("image/gif");
        if (usePersistence) {
                response.setContentLength(byteStream.size());
        }


        byteStream.writeTo(response.getOutputStream());
       } catch(IOException ioe) {
         reportError(response, "Error:  " + ioe);
      }
     }

     public void reportError(HttpServletResponse response, String message)
        throws IOException {
           response.sendError(response.SC_NOT_FOUND, message);
     }
    }




Thanx




0
Comment
Question by:wzm
6 Comments
 

Expert Comment

by:lEx
ID: 8015648
Can you put source code of output HTML file...?
0
 

Expert Comment

by:reliant_energy
ID: 8017032
The output of HTML file like IEx state please.
0
 

Author Comment

by:wzm
ID: 8021790
Here it is..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Web is Using Persistent Connection</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">PRUWeb is Using Persistent Connection</H1>
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b01lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b01lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b02lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b02lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b03lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b03lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b04lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b04lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b05lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b05lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b06lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b06lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b07lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b07lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b08lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b08lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b09lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b09lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b010lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b010lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b011lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b011lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b012lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b012lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b013lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b013lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b014lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b014lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b015lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b015lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b016lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b016lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b017lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b017lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b018lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b018lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b019lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b019lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b020lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b020lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b021lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b021lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b022lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b022lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b023lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b023lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b024lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b024lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b025lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b025lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b026lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b026lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b027lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b027lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b028lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b028lis.gif
<IMG SRC="/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b029lis.gif"
     WIDTH=6 HEIGHT=6 ALT="">
/servlet/coreservlets/bullets/b029lis.gif
</BODY></HTML>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:lEx
ID: 8024181
First : "/servlet/coreservlets.ImageRetriever?gifLocation=/bullets/b029lis.gif" - it's not a gif file source, if you use it in <img> tag result is nothing.
------------------------------------------------------

Second : I think what You want should be done this way :

return("<A SRC=\"" + file + "\"\n" +
                  "     WIDTH=6 HEIGHT=6 ALT=\"\"></A");  

NOT!!

return("<IMG SRC=\"" + file + "\"\n" +
                  "     WIDTH=6 HEIGHT=6 ALT=\"\">");

(may be I'm wrong)

-------------------------------------------------------

Any way <img> tag should contain Image path, not any else(Servlet too).
Can You describe what you trying to do with your ImageRetriever servlet??
0
 

Expert Comment

by:modulo
ID: 8194715
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/Q_20560453.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8221445
Saving this Q as a PAQ and refunding the points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question