I have the following error in my application:
getOutputStream () has already been called for this response.
Ok, the code snippet that is causing this error is as follows:
boolean hasLogoLogin = new BrandResourceDao().selectByTag(BrandResourceCnt.TAG_BRANDLOGOLOGIN) != null;
boolean hasLogoDefault = new BrandResourceDao().selectByTag(BrandResourceCnt.TAG_BRANDLOGODEFAULT) != null;
boolean hasLogoHight = new BrandResourceDao()
.selectByTag(BrandResourceCnt.TAG_BRANDLOGOHIGHLIGHTEDE) != null;
boolean hasBackground = new BrandResourceDao().selectByTag(BrandResourceCnt.TAG_BRANDBACKGROUND) != null;
That's nothing more than a select to check if the images saved at any given time in the application really are there. The code just below is repeated for each return of the above selects (Each one for its value).
<img id="imgLogoLogin"
<%=hasLogoLogin
? "src='loadImage.jsp?" + Params.TAG + "=" + BrandResourceCnt.TAG_BRANDLOGOLOGIN + "'" : ""%>
style="max-width: 325px; max-height: 200px; width: auto; height: auto;" />
And here the loadImage.jsp that searches the database for the image, converts and displays it in the application.
try {
String tag = request.getParameter(Params.TAG);
BrandResourceDao dao = new BrandResourceDao();
BrandResource brand = dao.selectByTag(tag);
if (brand != null) {
byte[] bytes = Base64.decode(brand.getValue());
response.setContentType("image/gif");
OutputStream oImage = response.getOutputStream(); <-- É culpa desse cara aí
oImage.write(bytes);
oImage.flush();
oImage.close();
}
} catch (Exception e) {
e.printStackTrace();
}
Please no swearing by the style of the tag (img) I will put it in the css in the future.
Well my doubt is: How to solve this? I need to change the structure is obvious. But I'm a beginner and I do not know how to do it. Does anyone have any ideas for making my life a little easier?