java 读取数据库图片地址,将图片展示在jsp页面(图片必须在服务器硬盘上,此方法才可成功)

衔接上篇博文,废话不多说。

流程说明:

页面点击‘加载图片’---》传入参数获取图片路径地址---》处理图片地址---》传到jsp页面<img src=" 图片地址"/>中

注:

在此之前需要将tomcat配置虚拟路径(图片必须在服务器硬盘上),tomcat和图片在同一台机器。(即tomcat访问本地图片)

正文:

List<String> imageList;

public List<String> getImageList() {
return imageList;
}

public void setImageList(List<String> imageList) {
this.imageList = imageList;
}

-----imageList的get、set方法不能省略,如是缺少,向jsp页面传值时,页面可能无法接收到,现象:页面什么也没有。

/***
* 加载更多图片信息
* @return
* @throws Exception
*/
public String  LoadPic() throws Exception{
String checkNo = this.getReqParam("checkNo"); // 超声号
imageList=service.getPicPath(checkNo);
this.setReqAttr("imageList", imageList);
return SUCCESS;
}

--------------------------以上是action中的方法----------------------

重点:

protected final String FilePath = "/upload/";//虚拟盘符配置(D:/image)tomcat-service.xml/<host>标签配置

发布你项目的tomcat配置:

server.XML:

    <Host appBase="webapps"autoDeploy="true"name="localhost"unpackWARs="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" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

添加如下虚拟硬盘:     

    <Context docBase="D:\image\" path="/upload" reloadable="true"/>

<Context docBase="CS_Report" path="/CS_Report" reloadable="true" source="org.eclipse.jst.jee.server:CS_Report"/></Host>


/***
 * 获取checkno号对应的图片地址信息
 * @param checkNo
 * @return
 * @throws Exception
 */
public List<String > getPicPath(String checkNo) throws Exception{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<String>list=new ArrayList<String>();
String sql = "select ImagesPath from Images where ReportId = "+ "\'" + checkNo + "\'";
conn=serviceDao.getConnection();
try {
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
String ImagesPath=FilePath+StringUtil.dealString(rs.getString("ImagesPath"));
System.out.println("组装后的图片地址信息:"+ImagesPath);
list.add(ImagesPath);
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
serviceDao.CLOSE(conn, ps, rs);
}
if(list.size()>0){
return list;
}
return null;
}



jsp页面:

<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %> 
<html>
<head>
<title>报告单图片详细信息</title>


<style type="text/css">
.style1 {
color: #FF0000;
font-size: 16px;
}
</style>
</head>
<script language="javascript">


function bigimg(i)
{
var zoom = parseInt(i.style.zoom,10)||100;
zoom += event.wheelDelta / 12;
if(zoom > 0 )
i.style.zoom=zoom+'%';
return false;
}图片放大缩小功能

</script>
</head>
<body>
<div  align="center" width="100%">
<div align="center"><p align="center" style="font-size:30;">嘻嘻嘻-图片详细</p></div>
<table width="80%">
<tbody>
<s:iterator value="imageList" id="listValue">
    <tr style="background:">
    <td><img alt="" src="<s:property />" onmousewheel="return bigimg(this)"></td>
    </tr>
</s:iterator>
</tbody>
</table>
<table align="center">
<tr>
<td align="center" ><input type="button" οnclick="window.history.back()" value="关闭"></td>
</tr>
</table>
</div>
</body>
</html>
<script type="text/javascript">
</script>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王大惑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值