导航:首页 > 编程语言 > 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怎么访问图片服务器相关的资料

热点内容
mac上用jsp写一个网页 浏览:6
word标准行间距 浏览:90
sw如何查看文件路径 浏览:329
jsp判断null 浏览:28
系统apk图标修改工具下载 浏览:703
jsp模型 浏览:431
承德货车运输哪个app好 浏览:907
华为5x书签文件夹路径 浏览:120
滑动t检验法程序 浏览:940
java百分数格式化 浏览:911
数据分析怎么看市场 浏览:993
魔兽联盟160升级攻略 浏览:234
iphone6plus直接购买 浏览:386
电脑升级后旧文件备份在哪里的 浏览:236
怎么禁止电脑文件到u盘外泄 浏览:217
pc端如何用modbustcp编程 浏览:336
富士xp142怎么编程 浏览:481
导航卡的数据是从哪里来的 浏览:168
为什么桌面会显示c盘某某文件 浏览:745
网页图片特效代码大全 浏览:277

友情链接