浅谈如何实现JSP上传图片无组件化

从JSP页使图片以JPEG编码后存储在指定文件夹中。这种JSP上传图片方式与组件上传相比似乎笨拙而又不能对文件属性进行操作,但的确可以轻松实现JSP上传图片的功能。

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比安国网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式安国网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖安国地区。费用合理售后完善,10年实体公司更值得信赖。

uploadimage1.jsp实现构建一个表单,提交用于为图片重命名的参数,以及图片文件。

 
 
 
  1. <%...@ page contentType="text/html; charset=gbk" %>   
  2. <%...@ page language="java" %>   
  3.      
  4.      
  5. </strong>DATABASE<strong> TITLE></strong>     </li> <li><strong><meta</strong> http-equiv="Content-Type" content="text/html; charset=gb2312"<strong>></strong>     </li> <li><strong> HEAD></strong>     </li> <li><strong><FORM</strong> METHOD=POST ACTION="uploadimage2.jsp"<strong>></strong>     </li> <li>人物:<strong><INPUT</strong> TYPE="text" NAME="name"<strong>><BR></strong>   </li> <li>图片:<strong><INPUT</strong> TYPE="file" NAME="image"<strong>><BR></strong>     </li> <li><strong><INPUT</strong> TYPE="submit" value="提交"<strong>></strong>   </li> <li><strong> FORM></strong>   </li> <li><strong> BODY></strong>     </li> <li><strong> HTML></strong>    </li> </ol></pre><p>uploadimage1.jsp实现获取用户提交参数为要存储的图片命名,以字符的形式获取上传的图片,进一步转化为输入流,最终完成JSP上传图片的功能。</p><pre> <ol> <li><strong><</strong>%...@ page contentType="text/html;charset=gb2312"%<strong>></strong>     </li> <li><strong><</strong>%...@ page import="java.util.*"%<strong>></strong>     </li> <li><strong><</strong>%...@ page import="java.text.*"%<strong>></strong>     </li> <li><strong><</strong>%...@ page import="java.io.*"%<strong>></strong>   </li> <li><strong><</strong>%...@ page import="com.sun.image.codec.jpeg.*"%<strong>></strong>   </li> <li><strong><</strong>%...@ page import="java.awt.image.*"%<strong>></strong>   </li> <li><strong><</strong>%...@ page import="java.awt.*"%<strong>></strong>   </li> <li>     </li> <li><strong><</strong>%...   </li> <li>  String name=request.getParameter("name");   </li> <li>  name=new String(name.getBytes("ISO-8859-1"));    </li> <li>  String ima=request.getParameter("image");    </li> <li> </li> <li>  try{   </li> <li>  String path=request.getRealPath("/");   </li> <li>  FileOutputStream ot = new FileOutputStream(path+name+".jpg");   </li> <li>// ServletOutputStream ot=response.getOutputStream(); //也可以直接输出显示   </li> <li>  FileInputStream in=new FileInputStream(ima);     </li> <li>  JPEGImageDecoder jpgCodec = JPEGCodec.createJPEGDecoder(in);   </li> <li>  BufferedImage image = jpgCodec.decodeAsBufferedImage();   </li> <li>  JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(ot);   </li> <li>  encoder.encode(image);     </li> <li>  in.close();   </li> <li>  ot.close();   </li> <li>  out.print("JSP上传图片成功!<strong><BR></strong>");   </li> <li>  //加载上传成功的图片   </li> <li>  out.print("<strong><IMG</strong> width=200 height=200 src='"+name+".jpg' <strong>/></strong>");   </li> <li>}   </li> <li>catch(Exception e)   </li> <li>{   </li> <li>System.out.print(e.toString());   </li> <li>}   </li> <li>%<strong>></strong>    </li> </ol></pre><p>实现JSP上传图片无组件化就为大家介绍到这里。</p><p>【编辑推荐】</p><ol><li>浅谈利用jspsmart实现文件上传下载</li><li>使用JSP页面生成PDF报表</li><li>JSP自定义标签定义步骤</li><li>详解测试JSP容器</li><li>介绍JSP HTTP服务器实现的以下特性</li></ol> <p> 文章标题:<a href="http://www.shufengxianlan.com/qtweb/news45/165045.html">浅谈如何实现JSP上传图片无组件化</a> <br> 标题URL:<a href="http://www.shufengxianlan.com/qtweb/news45/165045.html">http://www.shufengxianlan.com/qtweb/news45/165045.html</a> </p> <p> <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设公司</a>_<a href="https://www.cdcxhl.cn/" target="_blank">创新互联</a>,为您提供<a href="https://www.cdcxhl.com/news/shop/">商城网站</a>、<a href="https://www.cdcxhl.com/news/wxgzh/">微信公众号</a>、<a href="https://www.cdcxhl.com/news/dingzhiwangzhan/">定制网站</a>、<a href="https://www.cdcxhl.com/news/appkaifa/">App开发</a>、<a href="https://www.cdcxhl.com/news/yingxiao/">网站营销</a>、<a href="https://www.cdcxhl.com/news/zuo/">做网站</a> </p> <p class="adpic"> <a href="https://www.cdcxhl.com/service/ad.html" target="_blank" class="ad">广告</a> <a href="" target="_blank" class="adimg"><img src=""></a> </p> <p class="copy"> 声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a> </p> </div> <div class="newsmorelb"> <p>猜你还喜欢下面的内容</p> <ul> <li> <a href="/qtweb/news44/165044.html">购买的香港主机怎么老是不稳定?(新手租赁香港云主机如何选择带宽)</a> </li><li> <a href="/qtweb/news43/165043.html">专家传授网络安全“防身术”蹭网小心招“贼”</a> </li><li> <a href="/qtweb/news42/165042.html">面对不断扩大的技能鸿沟,云时代企业要主动出击</a> </li><li> <a href="/qtweb/news41/165041.html">快影为什么不能访问相册</a> </li><li> <a href="/qtweb/news40/165040.html">网站服务器怎么绑定域名?(域名怎么绑定站点号)</a> </li><li> <a href="/qtweb/news39/165039.html">XML学习交流(3)XML概念之一</a> </li><li> <a href="/qtweb/news38/165038.html">相关ADO.NET框架使用选项介绍</a> </li><li> <a href="/qtweb/news37/165037.html">冲动是魔鬼!云迁移不应只看在“钱”的份上</a> </li><li> <a href="/qtweb/news36/165036.html">云沙箱流量识别技术剖析</a> </li> </ul> </div> </div> <div class="col-lg-3 noneb"> <div class="bkright" style="margin-top: 0"> <p><a href="https://www.cdcxhl.com/news/jianshe/">网站建设知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news11/173861.html">搜索引擎优化SEO的三大误区</a> </li><li> <a class="text_overflow" href="/qtweb/news37/472937.html">Oracle10g如何用FIRALL来处理非连续数组</a> </li><li> <a class="text_overflow" href="/qtweb/news23/534423.html">Xshell轻松传输文件到Linux(xshell向linux传东西)</a> </li><li> <a class="text_overflow" href="/qtweb/news5/461355.html">解开Redis遇到的困难,找到正确的解答(redis问题答案)</a> </li><li> <a class="text_overflow" href="/qtweb/news17/346767.html">Redis突破性技术高并发负载处理(redis高并发负载)</a> </li><li> <a class="text_overflow" href="/qtweb/news31/326981.html">什么是sql通用防注入系统</a> </li><li> <a class="text_overflow" href="/qtweb/news16/28316.html">阿拉伯服务器?(阿拉伯服务器有哪些)</a> </li><li> <a class="text_overflow" href="/qtweb/news19/397569.html">Linux服务器搭建SVN服务器</a> </li><li> <a class="text_overflow" href="/qtweb/news43/54943.html">VS11之代码评审</a> </li><li> <a class="text_overflow" href="/qtweb/news2/472852.html">Redis线程池性能低下提升线程性能的新挑战(redis线程池慢)</a> </li><li> <a class="text_overflow" href="/qtweb/news12/340512.html">5个可以教你编程的游戏</a> </li><li> <a class="text_overflow" href="/qtweb/news43/26743.html">html反斜杠如何替换</a> </li><li> <a class="text_overflow" href="/qtweb/news29/441879.html">给RedisMake的必要性(redis需要make)</a> </li><li> <a class="text_overflow" href="/qtweb/news0/201900.html">其他域名的域名都建站正常打开国外主机</a> </li><li> <a class="text_overflow" href="/qtweb/news40/535690.html">网络跳线和网线的区别</a> </li> </ul> </div> <div class="bkright tag"> <p><a href="https://www.cdcxhl.com/hangye/" target="_blank">分类信息网站</a></p> <ul> <li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/pvc/" target="_blank">PVC花箱</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/muwu/" target="_blank">木屋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bolimo/" target="_blank">玻璃贴膜</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zzdb/" target="_blank">资质代办</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/blgds/" target="_blank">玻璃钢雕塑</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/fwjd/" target="_blank">房屋鉴定</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/ggsj/" target="_blank">广告设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/jianzhudonghua/" target="_blank">建筑动画</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/gaokongche/" target="_blank">高空作业车租赁</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/hldzj/" target="_blank">护栏打桩机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zkj/" target="_blank">公路钻孔机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/suliaodai/" target="_blank">塑料袋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/xiaojbc/" target="_blank">小搅拌车</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/led/" target="_blank">LED显示屏</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/gangting/" target="_blank">岗亭</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shayanfudiao/" target="_blank">砂岩浮雕</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="http://www.cdkjz.cn/fangan/finance/" target="_blank">金融行业网站建设方案</a>    <a href="https://www.scvps.cn/" target="_blank">网站域名</a>    <a href="http://seo.cdkjz.cn/quanwang/" target="_blank">网络推广外包</a>    <a href="https://www.cdcxhl.com/ssl/chengdu.html" target="_blank">SSL证书</a>    <a href="http://chengdu.cdcxhl.cn/dingzhi/ " target="_blank">成都定制网站</a>    <a href="http://www.cdymzj.com/" target="_blank">虚拟主机</a>    <a href="http://www.cdxwcx.cn/tuoguan/ershu.html" target="_blank">成都二枢机房</a>    <a href="https://www.cdcxhl.com/xiyun.html" target="_blank">移动服务器托管</a>    <a href="http://shengjin119.com/" target="_blank">四川胜锦安防</a>    <a href="http://www.zjjierui.cn/" target="_blank">广元双南建站</a>    <a href="https://www.cdxwcx.com/wangzhan/" target="_blank">成都网站建设</a>    <a href="http://www.pxzwz.com/" target="_blank">小谭建站</a>    <a href="http://www.cqcxhl.com/service/ds.html" target="_blank">重庆电商网站定制</a>    <a href="http://www.ycggtw.cn/" target="_blank">金羊影视传媒</a>    <a href="http://www.sczqjs.com/" target="_blank">中晴建设</a>    <a href="https://www.cdxwcx.com/" target="_blank">网站建设</a>    <a href="http://www.tjjierui.cn/" target="_blank">什邡做网站</a>    <a href="http://www.cxhljz.cn/" target="_blank">成都网站设计公司</a>    <a href="http://www.xhgfhy.com/ " target="_blank">不锈钢防护栏</a>    <a href="http://www.cdjbgc.com/" target="_blank">成都搅拌罐车</a>     </div> </div> <footer> <div class="carousel-inner footjz"> <div class="container"> <i class="icon iconfont zbw"></i> 高品质定制 <i class="icon iconfont"></i> 跨终端自动兼容 <i class="icon iconfont"></i> 节约开发成本 <i class="icon iconfont"></i> 开发周期短 <i class="icon iconfont"></i> 一体化服务 <button type="button" class="btn btn-default btn-lg" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 立即开始2800定制网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 2800定制网站建设</button> </div> </div> <div class="carousel-inner bqsy"> <div class="container"> <div class="lxfs"> <h4 class="yutelnone">028-86922220 13518219792</h4> <h4 class="yutelblock"><a href="tel:02886922220">028-86922220</a> <a href="tel:13518219792">13518219792</a></h4> <a class="btn btn-default" href="tencent://message/?uin=532337155&Site=&Menu=yes" role="button">网站建设<span>QQ</span>:532337155</a> <a class="btn btn-default" href="tencent://message/?uin=631063699&Site=&Menu=yes" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" role="button">网站制作<span>QQ</span>:532337155</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=631063699&version=1&src_type=web&web_src=oicqzone.com" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn-default nonea" href="tencent://message/?uin=1683211881&Site=&Menu=yes" role="button">售后QQ:1683211881</a> <div class="dz">创新互联建站专注: <a href="https://www.cdcxhl.com/" target="_blank">网站设计</a> <a href="https://www.cdcxhl.com/" target="_blank">网站制作</a> <a href="https://www.cdcxhl.com/" target="_blank">网站建设</a> <address>地址:成都太升南路288号锦天国际A幢10楼</address> </div> </div> <div class="bzdh dz"><img src="https://www.cdcxhl.com/imges/bottom_logo.png" alt="创新互联"> <p><a href="https://www.cdcxhl.com/menu.html" target="_blank">成都创新互联科技有限公司</a><br> Tel:400-028-6601(7x24h)</p></div> </div> </div> </footer> </body> </html> <script> $.getJSON ("../../qtwebpic.txt", function (data) { var jsonContent = { "featured":data } var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)]; $(".adpic .adimg").attr("href",random.link) $(".adpic img").attr("src",random.pic); }) </script>