Ⅰ 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才可以理解。我的例子仅作参考,还需要楼主多看看才行的。