jak wyświetlić obraz, który jest poza katalogiem serwerów w strtus
To pytanie jest kontynuacją mojego poprzedniego pytaniaUzyskiwanie dostępu do zewnętrznych plików w naszej aplikacji internetowej, faktycznie przesyłam plik za pomocą tagu struts<html:file property="file" />
Ale teraz chciałem pokazać przesłane obrazy z tej lokalizacji, ale otrzymujęsrc
lokalizacja jakhttp://localhost:9443/D:/resources/images/img1.jpg
co nie jest prawidłową ścieżką dla tego obrazu.
Jak uzyskać dostęp do tego obrazu, który znajduje się poza moim katalogiem serwera.
W ten sposób wysyłam odpowiedź AjaxBezwzględna ścieżka obrazów
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);
}
W ten sposób renderuję obrazy w 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'>";
});
Ale wimg
tag Otrzymuję ścieżkę obrazu jakohttp://localhost:9443/D:/resources/images/img1.jpg