S
Steve R. Burrus
i find myself in need of some help/assistance for a servlet that compiles
okay, but when I try to execute it in my browser I always get a
"java.lang.NullPointerException" server error!!! The servlet, incidentally,
is one that is supposed to render a image. I have no idea of what the
problem is, but many thanx to whoever can solve this one for me. I am very
frustrated by this! (Here is the servlet code) :
package org.my.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class My_Image extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("image/jpg");
ServletContext con = getServletContext();
InputStream in = con.getResourceAsStream("/MyBeautifulGirl1.jpg");
int i = 0;
byte[] b = new byte[1024];
OutputStream os = resp.getOutputStream() ;
while(( i = in.read(b)) != -1){
os.write(b, 0, i);
}
os.flush();
os.close();
}
}
okay, but when I try to execute it in my browser I always get a
"java.lang.NullPointerException" server error!!! The servlet, incidentally,
is one that is supposed to render a image. I have no idea of what the
problem is, but many thanx to whoever can solve this one for me. I am very
frustrated by this! (Here is the servlet code) :
package org.my.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class My_Image extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("image/jpg");
ServletContext con = getServletContext();
InputStream in = con.getResourceAsStream("/MyBeautifulGirl1.jpg");
int i = 0;
byte[] b = new byte[1024];
OutputStream os = resp.getOutputStream() ;
while(( i = in.read(b)) != -1){
os.write(b, 0, i);
}
os.flush();
os.close();
}
}