外服務器目錄這個問題是延續我剛纔的問題Accessing External Files Into Our Web Application,其實我使用Struts標籤<html:file property="file" />
如何顯示的圖像是在strtus
上傳文件,但現在我想表明從該位置上傳的圖片,但我得到的src
位置爲http://localhost:9443/D:/resources/images/img1.jpg
,這不是該圖像的有效路徑。
如何訪問我的服務器目錄之外的圖像。
這是怎麼了發送Ajax響應與絕對路徑圖像
public ActionForward getAjaxUploadedFiles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
String imagePath = "D:/resources/images/";
ArrayList<String> path = new ArrayList<String>();
File imageFile = new File(imagePath);
File imageFiles[] = imageFile.listFiles();
for (int i = 0; i < imageFiles.length; i++) {
path.add(imageFiles[i].getAbsolutePath());
}
PrintWriter out = response.getWriter();
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.setStatus(HttpServletResponse.SC_OK);
StringBuffer strXMl = new StringBuffer();
strXMl.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
strXMl.append("<start>");
for (String imagePth : path) {
strXMl.append("<imagePath>");
strXMl.append(imagePth);
strXMl.append("</imagePath>");
}
strXMl.append("</start>");
if(strXMl != null){
String Xml = strXMl.toString();
out.write(Xml);
System.err.println("XMl Reponse is: " + Xml);
}
else {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
out.flush();
return mapping.findForward(null);
}
這是我如何在JSP
$(response).find("imagePath").each(function() {
row = tblReportList.insertRow(0);
row.className="TableBordergray";
row.style.width="100%";
var imagePath = $(this).text();
cell = row.insertCell(0);
cell.innerHTML="<img src='" + imagePath + "' alt='" + imagePath + "' height='42' width='42'>";
});
渲染圖像,但在img
標籤我得到的圖像路徑爲http://localhost:9443/D:/resources/images/img1.jpg
什麼是src位置? –
感謝您的快速回復src的位置是D:/ resources/images /即在服務器目錄之外。 – Vishrant
發表評論的代碼,你得到這個。 –