衔接上篇博文,废话不多说。
流程说明:
页面点击‘加载图片’---》传入参数获取图片路径地址---》处理图片地址---》传到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 "%r" %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>