gpt4 book ai didi

java - 从数据库设置图像

转载 作者:行者123 更新时间:2023-11-29 12:43:51 24 4
gpt4 key购买 nike

我试图获取存储在 MYSQL 数据库中的图像并将其设置在 JSP 页面上,但出现以下错误:

Servlet.service() for servlet [SearchStudentControlling] in context with path [/Roomantech] threw exception [java.lang.IllegalStateException: getOutputStream() contain error so i didn,t the image in my jsp page

我使用以下代码来获取和设置图像。我在第 339 行收到错误,该错误不存在(我的代码只有 312 行)。我在过去的两个小时里一直在挣扎,但无法找出问题所在。

    session = request.getSession(false);
if(session!=null)
{
%>

<div style="width:100%;height:70%;">
<%@include file="header.jsp"%>

<div align="center" style="margin-top:150px">
<table align="center" width="73%;" height="100%;" class="abc">
<form action="nextpersonalinformation.do" method="post">
<strong><h2 style="color: darkblue;margin-bottom:30px;"><b><u>Person Information****</b></u></h2></strong>

<tr><td></td><td></td></tr>
<tr style="background-color: #003366;color: white;border-radius:5px"><td><h4 style="color: darkblue"><b style="color: white"> Your Hostel details****:</b></h4></td><td><b style="color: white">Enter Values:</b></td></tr>

<tr><td></td><td></td></tr>
<tr style="background-color: teal;font-size: 20px"></tr>

<%

ArrayList<PersonDetaildto>pa = (ArrayList<PersonDetaildto>)session.getAttribute("InformationPerson");
for(PersonDetaildto kk : pa)
{

System.out.println(kk.getFirst_nm()+" "+kk.getMiddle_nm());
%>
<tr>
<td>Person Image</td>
<td><img height="75px" width="75px" align="left" src="
<% byte[] imgbytes = kk.getPerson_image();
InputStream images = kk.getPersonimagee();
int size1=0;
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=logo.jpg");
while((size1=images.read(imgbytes))!= -1 )
{
response.getOutputStream().write(imgbytes,0,size1);
}
response.flushBuffer();
images.close();


%>"/></td>
</tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>

<tr>
</table>

</div>
<div style="width:100%;height:200px;">
</div>

<%
}

}
else
{
response.sendRedirect("welcome.do");
}

%>

<%@include file="footer.jsp"%>

</body>

</html>

最佳答案

编辑:您无法通过将字节插入 HTML 来添加图像(正如 Funtik 已经指出的那样)。
但是您可以通过将图像字节转换为 Base64 来插入它:

<img alt="YourEmbeddedImage" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgkAAAJNCAIAAAA0yXHVAAAACXBIWXMA..." /> 

关于java - 从数据库设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25725035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com