Java 将图像路径显示为数据库JSP Struts中的图像

Java 将图像路径显示为数据库JSP Struts中的图像,java,image,jsp,struts2,filepath,Java,Image,Jsp,Struts2,Filepath,我想从数据库中检索图像,数据类型为file。但是,我只能找到blob或其他类型的解决方案,而不能找到filepath。所以,我的问题是如何使用filepath显示图像 粗体字是我所困惑的。如何使用filepath实际显示图像。提前谢谢 Display.java-->与retrieve.jsp链接 public String execute() { try{ Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con =Driv

我想从数据库中检索图像,数据类型为file。但是,我只能找到blob或其他类型的解决方案,而不能找到filepath。所以,我的问题是如何使用filepath显示图像

粗体字是我所困惑的。如何使用filepath实际显示图像。提前谢谢

Display.java-->与retrieve.jsp链接

public String execute()
{

try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull","root","8899");
Statement st=con.createStatement();
ResultSet rs = st.executeQuery("select * from usertable");

    List li = null;
    li = new ArrayList();
    Mybean mb = null;

    while(rs.next())
        {
            mb = new Mybean();

            mb.setUserID(rs.getInt("userID"));
            **//mb.setUserImage(rs.get);** --> *In here, I am trying to setUserImage but I am not sure what is the correct way.*
            mb.setUserNRIC(rs.getString("userNRIC"));
            mb.setUserName(rs.getString("userName"));   
            mb.setUserEmail(rs.getString("userEmail"));
            mb.setUserPW(rs.getString("userPW"));   
            mb.setUserContact(rs.getInt("userContact"));
            mb.setUserAddress(rs.getString("userAddress")); 
            mb.setCatID(rs.getInt("catID"));
            mb.setCatTypeID(rs.getInt("catTypeID"));    
            mb.setSectionID(rs.getInt("sectionID"));
            mb.setStatus(rs.getString("status"));   

            li.add(mb);

        }

    request.setAttribute("disp", li);

    rs.close();
    st.close();
    con.close();

        }
    catch(Exception e){
        e.printStackTrace();
    }

        return SUCCESS;

}
retrieve.jsp-->以显示图像

<%
List l=(List)request.getAttribute("disp");
if(l!=null)
{

Iterator it=l.iterator();

while(it.hasNext())
{

Student.Mybean b=(Student.Mybean)it.next();

int userID = b.getUserID();
**//File userImage = b.getUserImage();**
String userNRIC = b.getUserNRIC();
String userName = b.getUserName();
String userEmail = b.getUserEmail();
String userPW = b.getUserPW();
int userContact = b.getUserContact();
String userAddress = b.getUserAddress();
int catID = b.getCatID();
int catTypeID = b.getCatTypeID();
int sectionID = b.getSectionID();
String status = b.getStatus();

%>
<tr>
<td><input type="checkbox" value="<%= userID %>" name="rdel"></td>

<td><%= userID %></td>
**<td><img src="<s:url action='userImage' />" /></td>** 
<td><%= userNRIC %></td>
<td><%= userName %></td>
<td><%= userEmail %></td>
<td><%= userPW %></td>
<td><%= userContact %></td>
<td><%= userAddress %></td>
<td><%= catID %></td>
<td><%= catTypeID %></td>
<td><%= sectionID %></td>
<td><%= status %></td>

使用rs.getBlob(columnName)@DarshanLila是mb.setUserImage((文件)rs.getBlob(“userImage”);是的,试试看。如果它不起作用,我们会找到其他的东西。@DarshanLila对于retrieve.jsp,我是否将这些放在显示图像的位置???文件userImage=b.getUserImage();“/>我建议您临时存储文件,并在显示时给出其真实路径。
String filePath = servletRequest.getSession().getServletContext().getRealPath("/");
File fileToCreate = new File(filePath, mb.userImageFileName);
FileUtils.copyFile(mb.userImage, fileToCreate);
ps.setString(1, mb.userImageFileName);