導航:首頁 > 編程語言 > jsp怎麼訪問圖片伺服器

jsp怎麼訪問圖片伺服器

發布時間:2024-08-19 09:29:05

Ⅰ 怎樣在jsp頁面上讀取伺服器磁碟上的文件

一、配置虛擬路徑

如:磁碟上保存的路徑為E:/file

虛擬路徑配置為/upload

在tomcat的server.xml中配置:

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"

pattern="%h %l %u %t &quot;%r&quot; %s %b" />

<!-- 在配置文件中加入的內容 --!>

<Context docBase="E:/file/" path="/upload/" reloadable="true"/>

</Host>

二、在jsp頁面上:

<img src="http://ip:埠號/upload/example.jpg"/>

java jsp 上傳圖片到伺服器之後,我想刪除伺服器上的圖片,哪位大俠曉得該怎麼實現,

File imgFile = new File(圖片路徑);
if(imgFile.exists()){
imgFile.delete();
}

Ⅲ 實在不明白了,怎麼才能在JSP之間顯示出圖片

我看見了好多次,今天回答你一下:
第一點,jsp是動態語言,運行在伺服器上,會被編譯成servlet執行。對tomcat你看tomcat根目錄下的work一層一層往下點你會看到,生成的servlet。
第二點、瀏覽器上要顯示文本圖片等等數據,要依賴html標記,在ie8以上,其他現代瀏覽器顯示圖片有兩種方法:
1、img標記的src屬性對應圖片url,所有瀏覽器都支持。
2、img標記src屬性對應,data:application/png,base64,【編碼成base64的圖片數據】,ie需要8以上支持。
第三點、瀏覽器請求jsp或者通過spring mvc這樣的框架間接請求jsp,那麼jsp最終是轉化成html的。
好有了上面的基礎:
圖片在你請求的單個jsp中顯示,只要把url寫對,jsp中生成的路徑一般你寫成絕對路徑,保證沒有問題。data:application/png,base64,【編碼成base64的圖片數據】這種格式的數據你不要base64編碼出問題,一定可以顯示。
假設你是n個jsp片段拼接成的一個最終顯示jsp頁面,jsp頁面之間是可以傳參的。把url或data數據當參數傳遞到下一個頁面。寫法如下:
<jsp:include page=」<%=pageSelectedAtRuntime%>」 flush=」true」 >
<jsp:param name=」fitstParamer」 value=」firstValue」>
<jsp:param name=」lastParamer」 value=」lastValue」>
</jsp:include>
這樣的參數可以用el表達式:${fitstParamer}給取出來,如果還不明白,別追問,認真學基礎去。

Ⅳ Jsp頁面中本地圖片顯示不了

還是給你個例子來的比較實際,sql操作台二進制數據
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*"%>
<html>
<body>
<%
/*
drop table imagetable;
create table imagetable
(
id int not null,
image image,
primary key (id)
)
*/

/*
//================ 一 、將文件寫入到資料庫的大欄位中begin=====================
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url ="jdbc:microsoft:sqlserver://127.0.0.1:1433;DataBaseName=zl";
Connection conn= DriverManager.getConnection(url,"sa","1234");
File file = new File("e:/1.jpg");
FileInputStream is=new FileInputStream(file);
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO imagetable (id,image)" + "VALUES (?, ?)");
stmt.setInt(1, 1);
stmt.setBinaryStream(2, is,(int)file.length());
stmt.executeUpdate();
stmt.close();
is.close();
out.println("恭喜你,你成功加入一張圖片!");
//===============將文件寫入到資料庫的大欄位中end=========================
*/

/*
//====================== 二、jsp顯示伺服器硬碟圖片示例 begin==============

FileInputStream is=new FileInputStream("e:/1.jpg");
response.reset();
response.setContentType("image/jpeg");
ServletOutputStream sos = response.getOutputStream();
byte[] buffer = new byte[1024];
int len=0;
while((len=is.read(buffer))>0){
sos.write(buffer,0,len);
}
sos.flush();
sos.close();

//=======================jsp顯示伺服器硬碟圖片示例 end===================
*/

//===================== 三、將資料庫的大欄點陣圖片還原到本地,並在網頁上顯示begin==============
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/test?user=root&password=eastsoftweb";
Connection conn= DriverManager.getConnection(url);
java.io.File file = new File("d:/temp/db.jpg");
FileOutputStream os=new FileOutputStream(file);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select nid,image from imagetable where nid=1");
rs.next();
byte[] buffer=rs.getBytes(2);
stmt.close();
os.write(buffer);
os.flush();
os.close();
out.println("query end");

//網頁上顯示
response.reset();
response.setContentType("image/jpeg");
ServletOutputStream sos = response.getOutputStream();
sos.write(buffer);
sos.flush();
sos.close();
//======================將資料庫的大欄點陣圖片還原到本地,並在網頁上顯示end===================

/*
//======================四、生成縮略圖begin==============================
File file = new File("d:/temp/1.JPG");
String newurl="d:/temp/2.jpg"; //新的縮略圖保存地址
Image src = javax.imageio.ImageIO.read(file); //構造Image對象
float tagsize=200;
int old_w=src.getWidth(null); //得到源圖寬
int old_h=src.getHeight(null);
int new_w=0;
int new_h=0; //得到源圖長
int tempsize;
float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//計算新圖長寬
BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //繪制縮小後的圖
FileOutputStream newimage=new FileOutputStream(newurl); //輸出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //近JPEG編碼
newimage.close();
//========================生成縮略圖end================================
*/
%>

Ⅳ 急!Jsp顯示不了上傳在伺服器的圖片!高手!!

圖片顯示不出來,一般是路徑錯誤~ 你可以到頁面上,查看源碼看下img的src是什麼。 看LZ寫的路徑,應該是相對路徑,在JSP里一般這種地方出現的較多的錯誤,是因為jsp頁面的小腳本里有一段href是關於basePath的,那是指當前頁面的相對位置是網站根目錄,那麼img的src也應該是相對網站根目錄的。 當然,這只是一個比較常見的jsp錯誤,不一定是LZ的原因,還是要看下,頁面源碼里的img的src是什麼。

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

可以把路徑保存到資料庫中,要在前端顯示的話。最好的方法就是在寫一個專門針對顯示圖片的action方法。將數據流寫出去,jsp中img標簽寫對應的顯示圖片的action方法的鏈接

Ⅶ jsp怎樣 顯示伺服器本地文件夾里的圖片

圖片文件名有中文,肯定讀不出來。
tomcat就這樣,中文名字的圖片,建議都改為英文或內數字吧。
<img src='http://ip+埠/虛擬路徑容/文件夾/文件名'>

Ⅷ java編程:怎麼用JSP(javabean)上傳一張圖片到伺服器的指定文件夾呢

網路,想飛社區,在資訊里,找 WEB前端 分類,有一篇文章:AJAX JAVA 上傳文件,可以參考,抱歉,貼不了地址。。。我只能這樣說了

閱讀全文

與jsp怎麼訪問圖片伺服器相關的資料

熱點內容
u盤內存還占著文件沒有了 瀏覽:551
python123在線編程手機怎麼用 瀏覽:511
保存配置文件的方法有哪些 瀏覽:827
php實時定位代碼 瀏覽:204
辦身份證需要攜帶哪些文件 瀏覽:249
品勝標准數據線多少A 瀏覽:689
生成手機版pdf文件 瀏覽:447
軟體是所有程序 瀏覽:183
飛貓網盤下載工具 瀏覽:749
鄭州長得聯利蘋果 瀏覽:643
esxi虛擬機版本 瀏覽:82
微信電腦版文件怎麼弄出來的 瀏覽:891
js日歷插件視頻 瀏覽:493
win10creators易升 瀏覽:324
淘寶橫向分類導航代碼 瀏覽:1
如何看自己視頻後台數據 瀏覽:65
ppt配色工具 瀏覽:883
微信pro病毒 瀏覽:16
如何查看網站結構層數 瀏覽:335
文件上傳時查找不到桌面圖片 瀏覽:686

友情鏈接