how to display image which is outside server directory in strtus

后端 未结 2 838
既然无缘
既然无缘 2020-12-20 07:32

This question is continuation to my previous question Accessing External Files Into Our Web Application, actually I am uploading file using struts tag

2条回答
  •  眼角桃花
    2020-12-20 07:57

    You can't render images in such way. Web server treated your image path as relative and add qualifying url location on the server. You should create an action to serve images, for example

    
    

    Then render HTML like

    cell.innerHTML="" + imagePath + "";
    

    Now, create the action that write the binary image data to the response output stream. Take a parameter path in the action that let you find a file for binary output. After the flushing output return null so struts should not forward the action further. You could also add headers to turn off a Cache-Control to make sure the images are retrieved from the server.

提交回复
热议问题