導航:首頁 > 文件處理 > jsp怎麼讀文件夾的圖片

jsp怎麼讀文件夾的圖片

發布時間:2022-10-20 15:00:18

Ⅰ jsp怎麼讀取本地圖片

java讀取本地圖片並在jsp中顯示

java:
public void showPicture() throws Exception
{

String picId = getRequest().getParameter("picId");
String pic_path = pointCardApplyManager.findPicturePath(picId);
System.out.println(pic_path);
FileInputStream is = new FileInputStream(pic_path);
int i = is.available(); // 得到文件大小
byte data[] = new byte[i];
is.read(data); // 讀數據
is.close();
response.setContentType("image/*"); // 設置返回的文件類型
OutputStream toClient = response.getOutputStream(); // 得到向客戶端輸出二進制數據的對象
toClient.write(data); // 輸出數據
toClient.close();
}

jsp:
<div align="left">
<img hspace="2" vspace="2" border="1" align="middle" height="50" width="50"
src="${ctx}/showPicture.action?picId=<s:property value='#image.resourceid'/>" onclick="selectForward('<s:property value='#image.resourceid'/>');">
</div>

javascript:

function selectForward(picId){
var objForm = document.applyForm;

var url="${ctx}/showPicture.action?picId="+picId;

var openStyle="dialogHeight:500px; dialogWidth:500px; status:no; help:no; scroll:auto";
var result = window.showModalDialog(url,window.document,openStyle);

return true;
}

顯示效果二:

jsp:
<div align="left" id="sam<s:property value='#sts.count'/>">
<img hspace="0" vspace="0" border="0" align="middle" height="50" width="50" onmouseover="displayDiv1('lag<s:property value='#sts.count'/>');displayDiv2('sam<s:property value='#sts.count'/>')"
src="${ctx}/showPicture.action?picId=<s:property value='#image.resourceid'/>">
</div>
<div align="left" id="lag<s:property value='#sts.count'/>" style="display:none">
<img hspace="0" vspace="0" border="0" align="middle" height="600" width="800" onmouseout="displayDiv1('sam<s:property value='#sts.count'/>');displayDiv2('lag<s:property value='#sts.count'/>')"
src="${ctx}/showPicture.action?picId=<s:property value='#image.resourceid'/>">
</div>

javascript:

function displayDiv1(name) {
document.getElementById(name).style.display="block";
}
function displayDiv2(name) {
document.getElementById(name).style.display="none";
}

Ⅱ jsp中如何打開文件對話框 並讀取圖片文件

<input type="file" name="myfile" />;點擊頁面按鈕後就出現打開文件對話框,選擇好一個文件就行了,文件讀取是自動的,瀏覽器自動讀取;不過,伺服器端需要編寫獲取文件的代碼,才能收到客戶端傳送的文件。

Ⅲ 關於JSP讀取圖片路徑

你用Myeclipse或eclipse編譯時難道沒有報錯??我猜你應該沒有用可以報錯工具進行代碼編寫的吧,你這個代碼在myeclipse中可是會直接報錯的,他會在 <img src="<%=Photo%>" 處的 Photo下劃紅線,因為找不到變數Photo,你的String Photo=rs.getString("Photo"); 放在了else中是局部變數,而="<%=Photo%>" 訪問不到。。。

Ⅳ jsp是什麼文件格式,怎麼打開

JSP(Java Server Pages)是由Sun Microsystems公司倡導、許多公司參與一起建立的一種動態網頁,打開方式如下:

1、我們先打開IE瀏覽器,如下圖所示:

Ⅳ java如何讀取文件夾中的圖片並在界面顯示

下面給你提供一個實現,該實現採用了代理模式。這個實現包含兩個文件,分別是Client.java和ImageIcoProxy.java,ImageIcoProxy.java負責了圖片的延遲載入,你可以修改為不延遲即可。

Client.java的代碼為:
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JFrame;

public class Client extends JFrame {
private static int IMG_WIDTH = 510;
private static int IMG_HEIGHT = 317;
private Icon imgProxy = null;
public static void main(String[] args) {
Client app = new Client();
app.setVisible(true);
}

public Client() {
super("Virture Proxy Client");
imgProxy = new ImageIcoProxy("D:/test.jpg", IMG_WIDTH, IMG_HEIGHT);
this.setBounds(100, 100, IMG_WIDTH + 10, IMG_HEIGHT + 30);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
super.paint(g);
Insets insets = getInsets();
imgProxy.paintIcon(this, g, insets.left, insets.top);
}
}

ImageIcoProxy.java的代碼為:
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;

public class ImageIcoProxy implements Icon {

private ImageIcon realIcon = null;
private String imgName;
private int width;
private int height;
boolean isIconCreated = false;
public ImageIcoProxy(String imgName, int width, int height) {
this.imgName = imgName;
this.width = width;
this.height = height;
}

public int getIconHeight() {
return realIcon.getIconHeight();
}

public int getIconWidth() {
return realIcon.getIconWidth();
}

public void paintIcon(final Component c, Graphics g, int x, int y) {
if (isIconCreated) {
//已經載入了圖片,直接顯示
realIcon.paintIcon(c, g, x, y);
g.drawString("Just Test", x + 20, y + 370);
} else {
g.drawRect(x, y, width-1, height-1);
g.drawString("Loading photo...", x+20, y+20);
synchronized(this) {
SwingUtilities.invokeLater(new Runnable() {

public void run() {
try {
Thread.currentThread().sleep(2000);
realIcon = new ImageIcon(imgName);
isIconCreated = true;
} catch (Exception e) {
e.printStackTrace();
}
c.repaint();
}

}
);
}
}
}

}

Ⅵ 手機上的JSP格式文件怎麼打開

JSP格式的文件在手機上是打不開的,只能夠用電腦打開。

以Windows7系統為例,演示電腦上如何打開JSP格式文件,步驟如下:

1、首先將JSP格式文件通過QQ發送到電腦上面,如圖所示。

Ⅶ JSP讀本地圖片

你用
document.getElementById('safecode').src='image.jpg?aaa=' + Math.random();
試試。

Ⅷ jsp怎樣讀出某個文件夾下的文件

讀取文件分位元組流FileInputStream和字元流FileReader。一般字元串處理用字元流FileReader.
比如說你要讀取c:\test.txt下的文本文件的內容。在jsp中嵌入如下代碼:
<%
FileReader reader = new FileReader(new File("c:\test.txt"));
//用readLine()方法一次讀取文件的一行放入該變數
String strCurrentLine = "";
while((strCurrentLine=reader.readLine()) != null){
System.out.println(strCurrentLine);
}
%>
java的IO操作用的是裝飾器模式。需要多看看jdk才可以理解。我的例子僅作參考,還需要樓主多看看才行的。

閱讀全文

與jsp怎麼讀文件夾的圖片相關的資料

熱點內容
機器語言編譯系統 瀏覽:662
java源文件編譯順序 瀏覽:78
數據壓縮的必要性 瀏覽:924
提出注釋程序java編譯 瀏覽:512
openwrt編譯出現錯誤能成功嗎 瀏覽:829
androidsdk20 瀏覽:606
為什麼互動作業顯示伺服器異常 瀏覽:592
androidchm閱讀 瀏覽:230
錘子手機給文件夾命名 瀏覽:211
加密列印機怎樣用 瀏覽:779
lol壓縮直播 瀏覽:632
催眠可以解壓嗎 瀏覽:379
java安卓環境 瀏覽:924
最重要的計算機演算法 瀏覽:161
帶式輸送機可編程式控制制器 瀏覽:794
長沙辦居住證在哪個app預約 瀏覽:745
python中計算圓面積代碼 瀏覽:861
中午吃壓縮餅干 瀏覽:996
信源編碼編解碼實驗 瀏覽:314
煮魚用哪個app好 瀏覽:439