-1

I am trying to Access images which are placed under static folder (resources/static/images) in SPRINGBOOT.

enter image description here

now I want to get image PATH, But getting null pointer exception.

 parameters.put(
            "imageLink",
            getClass().getResource("images/header.png").toString());
  • but in the above question i clearly mention that i have placed my images in static folder that's the problem. if i did like that then my question is duplicate. i don't want to know how to place image in jasper report. please read my question care fully. – Naimish vora Sep 07 '18 at 09:01

1 Answers1

2

You can reference the image directly in the report:

<image>
    <reportElement x="0" y="0" width="150" height="60"/>
    <imageExpression><![CDATA["static/images/header.png"]]></imageExpression>
</image>

Or pass it into the report by parameter as an Image instance:

BufferedImage image = ImageIO.read(getClass().getResource("/static/images/header.png"));
parameters.put("header", image);

And use it in the report like this:

<image>
    <reportElement x="0" y="0" width="150" height="60"/>
    <imageExpression><![CDATA[$P{header}]]></imageExpression>
</image>

Where header parameter class in report is as Object.


Or pass it as an URL instance:

URL headerUrl = getClass().getResource("/static/images/header.png");
parameters.put("header", headerUrl);

Where header parameter class in report is as URL.

<parameter name="header" class="java.net.URL" isForPrompting="false">
    <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>

Then the imageExpression in image element is the same as in previous example.

cgrim
  • 4,890
  • 1
  • 23
  • 42