0

I have a JSP (A) whose sole purpose is to return an image.

My main JSP (M) can't have direct access to this image path but needs to know if it exists (if not, JSP (A) will return a 404 code).

Here is (mostly) JSP (A) :

File img = new File(<complicated stuff to calculate the path>);
try
{
    BufferedImage bi = ImageIO.read(img);
    out.clear();
    response.setContentType("image/jpeg");
    ImageIO.write(bi, "jpg", response.getOutputStream());
}
catch(IIOException e)
{
    response.sendError(404);
}

I have tried the following in JSP (M) :

RequestDispatcher rd = request.getRequestDispatcher("../JSP_A");
rd.include(request, response);
System.out.println("### " + response.getStatus());

I get an error:

error: cannot find symbol
symbol:   method getStatus()
location: variable response of type HttpServletResponse

I don't understand because getStatus() is of course a method of HttpServletResponse.

Liios
  • 93
  • 8
  • provide more code. – Ye Win Nov 04 '16 at 10:06
  • @YeWin: oh please no. Basile: which IDE are you using? If Eclipse, then this is the answer to your http://xyproblem.info: http://stackoverflow.com/q/4076601 – BalusC Nov 04 '16 at 10:16
  • Ok @BalusC , I just assume it's related with other code in his servlet method. – Ye Win Nov 04 '16 at 10:19
  • My Eclipse is correctly configured : this is the first time I have such error and some methods do work (getHeader() for exemple). Maybe I don't use the correct way of calling another JSP ? – Liios Nov 04 '16 at 10:24
  • 1
    Basile, the mentioned method was introduced in Servlet 3.0. Your concrete problem strongly suggests that your Eclipse project is misconfigured to use an arbitrarily downloaded Servlet API library (which happens to be of an older version) instead of relying on the one provided by the target runtime. This is a pretty common beginner's mistake which is fleshed out in the given duplicate. – BalusC Nov 04 '16 at 12:22

0 Answers0