當前位置:首頁 » 文件管理 » jsp圖片上傳顯示

jsp圖片上傳顯示

發布時間: 2022-05-18 07:49:21

㈠ jsp照片上傳問題 怎麼顯示啊

你路徑存好了,然後把路徑返回給頁面,就可以顯示出來了,不過像這些上傳圖片的功能 為了讓客戶體驗更好,一般都是使用ajax 非同步上傳 struts+hibernate 不是 struct+hibernate 吧?

㈡ jsp+servlet 上傳圖片並顯示出來

其實你這個擋也顯示圖片其實很簡單的,
你的需求無非是兩個
1.servlet上傳文件(圖片)
2.點擊 瀏覽 圖標,然後選擇圖片文件,然後就可以在頁面中的某個地方看到圖片

是這兩個需求么?
首先說第二個吧。
你上傳圖片之後,就馬上觸發js函數,內容為
var PicPath = document.getElementById("yourfile").value;
document.getElementById("yourDiv").innerHTML="<IMG src="+PicPath+"/>";
OK了

第一個嘛就無所謂說了,不過我還是貼一個代碼吧,
public void upLoadFile(HttpServletRequest request, HttpServletResponse response) {
PrintWriter out = null;
response.setCharacterEncoding("UTF-8");
//實例化文件工廠
FileItemFactory factory = new DiskFileItemFactory();
//配置上傳組件ServletFileUpload
ServletFileUpload upload = new ServletFileUpload(factory);
try {
out = response.getWriter();
//從request得到所有上傳域的列表
List<FileItem> list = upload.parseRequest(request);

for (FileItem item : list) {
//isFormField判斷一個item類對象封裝的是一個普通的表單欄位還是文件表單欄位。
// 如果item是文件域,則做出如下處理:
if (!item.isFormField()) {

//上傳文件域的Name
String fileName = item.getName();

//截取擴展名
int idx = fileName.lastIndexOf(".");
String extension = fileName.substring(idx);

//獲取文件名
String name = new Date().getTime() + extension;

//得到文件夾的物理路徑
String path = this.getServletContext().getRealPath("\\upload");

//創建一個File
File file = new File(path + "\\" + name);
FileOutputStream o = new FileOutputStream(file);
InputStream in = item.getInputStream();
try {
LoadProcessServlet.process = 0;
LoadProcessServlet.total = 100;
LoadProcessServlet.isEnd = false;
LoadProcessServlet.total = item.getSize();
byte b[] = new byte[1024];
int n;
while ((n = in.read(b)) != -1) {
LoadProcessServlet.process+=n;
o.write(b, 0, n);
System.out.println("實際:"+LoadProcessServlet.process);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
LoadProcessServlet.isEnd = true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

}

㈢ jsp用upload實現圖片上傳時圖片不能顯示出來(沒有顯示錯誤)

程序開發中,盡量不要使用相對路徑,容易出問題。你的問題很好解決

在文件最頭上添加以下代碼

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
然後圖片路徑這樣寫
<img src="<%=basePath%>upload/<%=fileName%>" />

㈣ jsp上傳圖片後怎麼實時顯示出來

<script>
function setImagePreview() {
var docObj=document.getElementById("doc");
var imgObjPreview=document.getElementById("preview");
if(docObj.files && docObj.files[0]){
//火狐下,直接設img屬性
imgObjPreview.style.display = 'block';
imgObjPreview.style.width = '300px';
imgObjPreview.style.height = '120px';
//imgObjPreview.src = docObj.files[0].getAsDataURL();
//火狐7以上版本不能用上面的getAsDataURL()方式獲取,需要一下方式
imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
}else{
//IE下,使用濾鏡
ocObj.select();
var imgSrc = document.selection.createRange().text;
var localImagId = document.getElementById("localImag");
//必須設置初始大小
localImagId.style.width = "250px";
localImagId.style.height = "200px";
//圖片異常的捕捉,防止用戶修改後綴來偽造圖片
try{
localImagId.style.filter=
"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
localImagId.filters.item
("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
}catch(e){
alert("您上傳的圖片格式不正確,請重新選擇!");
return false;
}
imgObjPreview.style.display = 'none';
document.selection.empty();
}
return true;
}
</script>
<body>
<input type=file name="doc" id="doc" onchange="javascript:setImagePreview();">
<p><div id="localImag">
<img id="preview" width=-1 height=-1 style="diplay:none" />

㈤ 用Java Web的jsp製作圖片上傳和顯示如何實現

用jspSmartUpload組件來實現,用jsp+servlet在Servlet里實現的代碼:

PrintWriter out = response.getWriter();
int count = 0;
// 實例化上傳控制項對象
SmartUpload su = new SmartUpload();
// 初始化操作
su.initialize(config, request, response);

// 設置上傳文件最大位元組數
su.setTotalMaxFileSize(100000);

//
try {
//禁止上傳指定擴展名的文件
su.setDeniedFilesList("ext,bat,jsp");
} catch (SQLException e1) {
e1.printStackTrace();
}

try {
// 上傳文件到伺服器
su.upload();

File fileup = new File(request.getRealPath("upload"));
if(!fileup.exists()){
// 創建目錄
fileup.mkdir();
}
// 處理多個文件的上傳
for(int i = 0;i < su.getFiles().getCount();i++){
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if(!file.isMissing()){ // 如果文件有效
// 保存文件到指定上傳目錄
file.saveAs("/upload/new."+file.getFileExt(), su.SAVE_VIRTUAL);
count = su.save("/upload");
}
}

} catch (SmartUploadException e) {

e.printStackTrace();
}
out.println(count +"file(s) uploaded");

如果你對這個上傳組件不了解,最好是先去查查用法。。。

㈥ JSP上傳圖片後的顯示問題

你用的pathFile不對,也就是 img 的src路徑不對
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
<img src="<%=basePath +pathFile %>" width="229" height="200">

㈦ 求大神,jsp上上傳圖片,並顯示出來,將其相對路徑記入資料庫


Stringtime=newSimpleDateFormat("yyyyMMddHHmmss")

.format(Calendar.getInstance().getTime());//得到系統時間

//上傳技術

SmartUploap=newSmartUpload();


//進行初始化


up.initialize(this.getServletConfig(),request,response);


//開始上傳


try{

up.upload("utf-8");//設置編碼方式。

intid=Integer.parseInt(up.getRequest().getParameter("id"));//商品編號

SmartFilessf=up.getFiles();//得到上傳的所有圖片

SmartFilefile=sf.getFile(0);//根據索引得到上傳圖片多個圖片可以用循環:

Stringtype=file.getFileExt();//得到圖片後綴名

Stringfolder="tp/";//指定文件夾

Stringpath=folder+time+"."+type;//路徑

System.out.println(path+"路徑");

file.saveAs(request.getRealPath("/")+path);//保存圖片


}catch(Exceptione){

e.printStackTrace();

}

//你搞個郵箱我把SmartUploadjar包發給你吧。 //設置from提交

/*<form action="SellerServet" method="post"

enctype="multipart/form-data">*/ // 加上enctype="multipart/form-data

㈧ jsp怎麼實現瀏覽本地圖片選中上傳到頁面上,並且保存在資料庫,從資料庫讀取也可以顯示在頁面上

資料庫不能保存圖像,但是能保存圖像名,我給你個思路,用戶上傳後使用uid方法將圖片重命名,然後將新的名稱存在資料庫,圖片保存在一個已知路徑,然後頁面載入只需要將圖片src設置成"路徑/資料庫查詢結果。(建議通過id查詢)"

㈨ jsp中,我在一個頁面,用jspsmartupload上傳圖片,上傳成功後,跳回來,想顯示此圖,但是顯示不出來。

1.上傳失敗,圖片位元組大小為0KB,需重新上傳覆蓋。
2.源文件的所在的目錄路徑不對。
3.圖片命名的格式不支持:不要用漢字為圖片命名,最好是純英文字母,一般數字也可以。
不知道能幫上不

㈩ jsp上傳圖片到tomcat伺服器後,怎麼在頁面顯示

你可能把伺服器的相對地址保存到資料庫里去,如在updateimg文件夾下的2012010501.jsp文件
地址就是:/updateimg/2012010501.jsp 前面加上服務的訪問地址

熱點內容
php給文本框賦值 發布:2024-05-06 03:21:24 瀏覽:25
androidjsonkey 發布:2024-05-06 03:07:31 瀏覽:730
python主線程子線程 發布:2024-05-06 03:07:20 瀏覽:763
android系統截屏 發布:2024-05-06 02:57:51 瀏覽:776
android居左 發布:2024-05-06 02:40:26 瀏覽:45
網頁設置的密碼如何刪除 發布:2024-05-06 02:20:30 瀏覽:926
如何查看snmp配置信息 發布:2024-05-06 02:19:48 瀏覽:489
預科編程 發布:2024-05-06 02:19:42 瀏覽:140
壓縮比英文 發布:2024-05-06 01:56:35 瀏覽:173
數字php 發布:2024-05-06 01:53:10 瀏覽:743