现在我正尝试显示数据库中的多个图像。当我单击一个按钮时,它会打到servlet并使用请求分派器在View.jsp中仅显示单个图像。帮助我一次检索多个图像
请现在帮助我获取更多图像,我正尝试从数据库中显示多个图像..当我单击按钮时,它会打到servlet并使用请求分派器在View.jsp中仅显示单个图像。时间
package viewProducts;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ViewPro")
public class ViewPro extends HttpServlet {
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ravi", "root", "root");
ps = con.prepareStatement("select * from album");
rs=ps.executeQuery();
while (rs.next()) {
byte[] content = rs.getBytes("Image");
// response.setContentType(getServletContext().getMimeType(imageName));
response.setContentLength(content.length);
response.getOutputStream().write(content);
request.setAttribute("Image", content);
RequestDispatcher rd=request.getRequestDispatcher("VP.jsp");
rd.forward(request, response);
}
response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
} catch (SQLException e) {
throw new ServletException("Something failed at SQL/DB level.", e);
}
}
}