如标题所说就是调用网页打印器来打印表格,先说以下具体实现步骤:
-
将数据查询出来(因为网页的打印器是打印的当前网页的内容,所以需要新建一个页面专门用来打印数据用)
-
查询出来的数据保存到请求中,在把请求请求转发给打印的jsp页面,jsp通过el表达式获取传过来的值,循环打印。
-
Js调用网页的打印器,完成。
代码部分:
Servlet部分:将查询出来的数据用集合来接收,再把集合保存请求中,再把请求转发到需要打印的jsp页面
Jsp部分:用c:forEach遍历集合的值-
-
<caption>消费报表</caption>
-
<thead>
-
<tr>
-
<th>房台类别</th>
-
<th>房台号</th>
-
<th>项目名称</th>
-
<th>单价</th>
-
<th>数量</th>
-
<th>折扣</th>
-
<th>消费金额</th>
-
<th>单号</th>
-
</tr>
-
<c:forEach items="${lists}" var="user">
-
<tr>
-
<th>${user.RTableCategory}</th>
-
<th>${user.RTableCode}</th>
-
<th>${user.itemName}</th>
-
<th>${user.price}</th>
-
<th>${user.count}</th>
-
<th>${user.discount}</th>
-
<th>${user.jinnt}</th>
-
<th>${user.oneMark}</th>
-
</tr>
-
</c:forEach>
-
</thead>
-
Js部分:调用浏览器打印器
1. $(function(){
2. window.print();//调用浏览器的打印功能
3. });
效果图:样式没怎么调,所以有点不太好看。