关于开发高手2004第8期中,<jsp创建基于WEB的动态图表>一文中的些许错误

博客指出在JSP中直接向response输出流写图片信息,Tomcat会报错,原因是JSP转换成Servlet时会造成流向错误。改用Servlet可避免此问题,还能实现图片合成等功能。此外,不建议使用sun的包,后续考虑用Java包替代。

声明下,这个错误是在实践过程中发现的,并不代表没有解决办法.

 

文中在jsp中直接用 outputstream=response.getoutputstream(); 获得response的输出流,然后向这个输出流写image信息. 在实际运行中,tomcat会报错, 不知作者是怎么解决的. 经过研究,发现这个问题是由于jsp转换成servlet的时候形成的, jsp 在转换成servlet后的运行过程中,也会要得到response的输出流(我是这么理解的),这样会造成流向错误,  tomcat后台会报错, 但前台网页同样能输出图片流.

改用servlet后, 由于能控制到doget,dopost的方法, 不用jsp再翻译成servlet,直接运行servlet, 这样就不会报错了.

而且servlet能够配成各种URL, 在当前的项目中,是配成/makepic/output.jpg 方式,直接生成图片流输出, 然后在网页中调用 《IMG src="”/makepic/output.jpg?picname=xxx”"》  运行的. 可以实现图片合成; 和别的项目共用一组图片,而不用把图片放在根目录下. 还是有很多好处的.

还有一个. 文章中使用了sun的包, 这个是不建议使用的, 还有一种方法,直接使用java的包, 下次修改帖出来..

 

也许JSP中有解决的办法... 也可能是我没仔细看这篇文章..因为文章发表的时候,正好前一天刚好解决了问题. 就懒得再详细看了. :)

{%extends 'base.html'%} {%block content%} <div class=right> <div class=top> <div class=tool> <div class=class-info></div> <form action=/scores/ class=search-form> <span>班级:</span> <select name=grade> <option value selected>请选择班级</option> <option value=6> 1年2班</option> <option value=7>1年3班</option> <option value=8>1年1班 </option> <option value=9>1年4班</option> <option value=10> 1年5班 </option> </select> <span>姓名/学号:</span> <input type=text name=search value> <input type=submit value=搜索 id=search> </form> </div> <div class=actions> <button type=button class=add id=add>新增</button> <button type=button class=del id=bulkDel>批量删除</button> <button type=button class=import id=import>导入</button> <button type=button class=export id=export>导出</button> </div> </div> </div> <div class=bottom> <table> <thead> <tr> <th><input type=checkbox id=select-all></th> <th>考试名称</th> <th>姓名</th> <th>班级</th> <th>学号</th> <th>语文</th> <th>数学</th> <th>英语</th> <th>操作</th> </tr> </thead> <tbody> {%%} <tr> <td><input type=checkbox name=score_ids value=27></td> <td>1年级期中考试</td> <td>张婷婷</td> <td>1年1班</td> <td>G565584201410153486</td> <td>68.00</td> <td>81.00</td> <td>71.00</td> <td> <a href= > 查看</a > <a href=http://127.0.0.1:8000/scores/update/27/ class=edit>编辑</a > <a href=http://127.0.0.1:8000/scores/delete/27/ class=btn-danger>删除</a > </td> </tr> </tbody> </table> <div class=pagination> <div> <div> <span>第1页/共1页</span> </div> </div> </div> </div> </div> <script type="text/javascript"> document.getElementById('add').addEventListener('click', function() { Swal.fire({ position: "top-end", html: `<iframe src="{%url 'student_create'%}" width="100%" height="800px" frameborder="0"></iframe>`, width:600, showConfirmButton:false }); }) ; </script> {% endblock %}
最新发布
12-12
```html {% extends 'base.html' %} {% block content %} <div class="right"> <div class="top"> <div class="tool"> <div class="class-info"></div> <form action="/scores/" class="search-form"> <span>班级:</span> <select name="grade"> <option value="" selected>请选择班级</option> <option value="6"> 1年2班</option> <option value="7">1年3班</option> <option value="8">1年1班 </option> <option value="9">1年4班</option> <option value="10"> 1年5班 </option> </select> <span>姓名/学号:</span> <input type="text" name="search" value=""> <input type="submit" value="搜索" id="search"> </form> </div> <div class="actions"> <button type="button" class="add" id="add">新增</button> <button type="button" class="del" id="bulkDel">批量删除</button> <button type="button" class="import" id="import">导入</button> <button type="button" class="export" id="export">导出</button> </div> </div> </div> <div class="bottom"> <table> <thead> <tr> <th><input type="checkbox" id="select-all"></th> <th>考试名称</th> <th>姓名</th> <th>班级</th> <th>学号</th> <th>语文</th> <th>数学</th> <th>英语</th> <th>操作</th> </tr> </thead> <tbody> {%%} <tr> <td><input type="checkbox" name="score_ids" value="27"></td> <td>1年级期中考试</td> <td>张婷婷</td> <td>1年1班</td> <td>G565584201410153486</td> <td>68.00</td> <td>81.00</td> <td>71.00</td> <td> <a href=""> 查看</a> <a href="http://127.0.0.1:8000/scores/update/27/" class="edit">编辑</a> <a href="http://127.0.0.1:8000/scores/delete/27/" class="btn-danger">删除</a> </td> </tr> </tbody> </table> <div class="pagination"> <div> <div> <span>第1页/共1页</span> </div> </div> </div> </div> </div> <script type="text/javascript"> document.getElementById('add').addEventListener('click', function() { Swal.fire({ position: "top-end", html: `<iframe src="{% url 'student_create' %}" width="100%" height="800px" frameborder="0"></iframe>`, width: 600, showConfirmButton: false }); }); </script> {% endblock %} ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值