java實(shí)現(xiàn)圖片上傳并顯示 java web項(xiàng)目中圖片上傳瀏覽的路徑?
java web項(xiàng)目中圖片上傳瀏覽的路徑?字符串文件名=(字符串)請(qǐng)求.getAttribute(“fileBrowser”)如果(fileName!=空值(&A)文件名.trim().length(
java web項(xiàng)目中圖片上傳瀏覽的路徑?
字符串文件名=(字符串)請(qǐng)求.getAttribute(“fileBrowser”)
如果(fileName!=空值(&A)文件名.trim().length()> 0){
File File=新文件(文件名)文件.getPath()]}
在servlet或actoin中。
過去傳遞的頁面只是一個(gè)字符串,需要單獨(dú)處理。
另一種方法是使用Ajax提交。
---
<form name=“form1”action=“/LVMH/management/refresh Data Chinese”><input type=“file”name=“fileBrowser”size=“50”onchange=“readFile(this)”/><input type=“submit”id=“box BTN”> update</input></form>
您的圖片在后臺(tái)存儲(chǔ)在哪里?如果它存儲(chǔ)在服務(wù)器的硬盤中,您可以使用Tomcat配置虛擬路徑來訪問磁盤上的圖片。如果有類似的東西。阿里云,你可以直接使用這個(gè)網(wǎng)址。如果有一個(gè)數(shù)據(jù)庫,并且圖像是Base64,則可以將Base64字符串發(fā)送到前端并在其前面拼寫前綴