Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

Re: How do I ........?

Martin Gainty

2006-11-12

Replies:

I dont think you can use special characters as your filename
so ren your image to image.jpg then re-get using

logo = getServletContext().getResourceAsStream("image.jpg");

M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its
contents
----- Original Message -----
From: "Steve R Burrus" <burrus1@(protected)>
To: "Tomcat Users List" <users@(protected)>
Sent: Sunday, November 12, 2006 7:06 PM
Subject: Re: How do I ........?


> here is the entire code for the image servlet which I seem to be
> repeatedly getting that NullPointerException java exception. Any ideas
> what the problem is ? :
>
>                   package coreservlets;
>
>                   import java.io.*;
>                   import javax.servlet.*;
>                   import javax.servlet.http.*;
>
> public class Image_File extends HttpServlet {
>   public void doGet( HttpServletRequest rq, HttpServletResponse rp )
> throws
>                                     ServletException,
> IOException {
>     rp.setContentType( "image/jpeg" );
>
>     ServletContext sc = getServletContext ();
>     InputStream in = sc.getResourceAsStream("/Sexy_Laundry_Girl!.JPG");
>
>     int r = 0;
>     byte[] by = new byte[4096];
>
>     OutputStream os = rp.getOutputStream();
>     while( ( r = in.read(by)) != -1) {
>         // if (r in= null)
>        os.write(by, 0, r);
>     }
>     os.flush();
>     os.close() ;
>  }
> }
>
>
> Martin Gainty wrote:
>
>>you can always wrap your accesor in a simple try/catch block as in
>>try
>>{
>> Image logo=null;
>> logo = Toolkit.getDefaultToolkit().getImage("images/splash.png");
>>}
>>catch(NullPointerException excp)
>>{
>> log.debug("NullPointerException thrown while retreiving image images/splash.png");
>> System.out.println("NullPointerException thrown while retrieving images/splash.png");
>>}
>>
>>Anyone else?
>>
>>M-
>>This e-mail communication and any attachments may contain confidential and privileged information for the use of the
>>designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
>>this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its
>>contents
>>----- Original Message -----
>>From: "Steve R Burrus" <burrus1@(protected)>
>>To: <users@(protected)>
>>Sent: Sunday, November 12, 2006 5:52 PM
>>Subject: How do I ........?
>>
>>
>>
>>
>>>I know that this question of mine has been asked/answered in this
>>>group, but I was wondering how do I go about checking for a null value?
>>>I feel the need to do this in a servlet file that incorporates an image
>>>into it.
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To start a new topic, e-mail: users@(protected)
>>>To unsubscribe, e-mail: users-unsubscribe@(protected)
>>>For additional commands, e-mail: users-help@(protected)
>>>
>>>  
>>>
>>>
>>
>
©2008 junlu.com - Jax Systems, LLC, U.S.A.