如何实现JSP上传图片无组件化-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

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

本篇内容介绍了“如何实现JSP上传图片无组件化”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

创新互联建站是一家专业提供萍乡企业网站建设,专注与成都网站建设、网站设计H5场景定制、小程序制作等业务。10年已为萍乡众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。

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

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

<%...@ page contentType="text/html; charset=gbk" %>   <%...@ page language="java" %>             DATABASETITLE>     <meta http-equiv="Content-Type" content="text/html; charset=gb2312">     HEAD>     <FORM METHOD=POST ACTION="uploadimage2.jsp">     人物:<INPUT TYPE="text" NAME="name"><BR>   图片:<INPUT TYPE="file" NAME="image"><BR>     <INPUT TYPE="submit" value="提交">   FORM>   BODY>     HTML></pre><p>uploadimage1.jsp实现获取用户提交参数为要存储的图片命名,以字符的形式获取上传的图片,进一步转化为输入流,最终完成JSP上传图片的功能。</p><pre><%...@ page contentType="text/html;charset=gb2312"%>     <%...@ page import="java.util.*"%>     <%...@ page import="java.text.*"%>     <%...@ page import="java.io.*"%>   <%...@ page import="com.sun.image.codec.jpeg.*"%>   <%...@ page import="java.awt.image.*"%>   <%...@ page import="java.awt.*"%>        <%...     String name=request.getParameter("name");     name=new String(name.getBytes("ISO-8859-1"));      String ima=request.getParameter("image");       try{     String path=request.getRealPath("/");     FileOutputStream ot = new FileOutputStream(path+name+".jpg");   // ServletOutputStream ot=response.getOutputStream(); //也可以直接输出显示     FileInputStream in=new FileInputStream(ima);       JPEGImageDecoder jpgCodec = JPEGCodec.createJPEGDecoder(in);     BufferedImage image = jpgCodec.decodeAsBufferedImage();     JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(ot);     encoder.encode(image);       in.close();     ot.close();     out.print("JSP上传图片成功!<BR>");     //加载上传成功的图片     out.print("<IMG width=200 height=200 src='"+name+".jpg' />");   }   catch(Exception e)   {   System.out.print(e.toString());   }   %></pre><p>“如何实现JSP上传图片无组件化”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!</p>            
            
                        <br>
            分享文章:如何实现JSP上传图片无组件化            <br>
            分享路径:<a href="http://kswsj.cn/article/geepci.html">http://kswsj.cn/article/geepci.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dsehoge.html">css父子样式,css 父子关系</a>
                </li><li>
                    <a href="/article/dsehogc.html">是windows系统的简单介绍</a>
                </li><li>
                    <a href="/article/dsehodh.html">nosql主要技术,nosql数据库的主要技术特点包括</a>
                </li><li>
                    <a href="/article/dsehods.html">包含去除windows系统的词条</a>
                </li><li>
                    <a href="/article/dsehoip.html">php查询数据库并赋值,PHP调用数据库</a>
                </li>        </ul>
    </div>
</div>
<div class="line"></div>
<!--底部-->
<footer id="5">
    <div class="foot1 container">
        <div class="list">
            <div class="item">
                <a href="javascript:;">
                    <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span>
                    <strong>关注我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>索要报价</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>我要咨询</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>找到我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>投诉建议</strong>
                </a>
            </div>
        </div>
        <div class="tel">
            <dl>
                <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br>
                <span>也许您需要专业的服务,欢迎来电咨询</span>
            </dl>
            <dl>
                <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br>
                <span>您的需求,是我们前进的动力</span>
            </dl>
        </div>
    </div>
    <div class="friend">
        <div class="container">
            <span class="tit">友情链接:</span>
            <div class="inner">
                <a href="https://www.cdcxhl.com/pinpai.html" target="_blank">成都品牌网站建设公司</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文发稿投放平台</a><a href="https://www.cdcxhl.com/wangzhandingzhi.html" target="_blank">成都企业网站定制</a><a href="https://www.cdcxhl.com/xiyun.html" target="_blank">移动主机托管</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">成都机柜租用</a><a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">西云移动机房</a><a href="https://www.cdcxhl.com/google.html" target="_blank">谷歌推广</a><a href="https://www.cdcxhl.com/hangyead/" target="_blank">广告投放</a><a href="https://www.cdcxhl.com/xiaochengx.html" target="_blank">成都小程序开发</a><a href="https://www.cdcxhl.com/zuyong/" target="_blank">成都物理服务器租用</a><a href="https://www.cdcxhl.com/link/" target="_blank">买卖链接</a><a href="https://www.cdcxhl.com/douyin/" target="_blank">短视频拍摄</a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">成都营销型网站建设</a><a href="https://www.cdcxhl.com/xiaochengx.html" target="_blank">微信小程序开发</a><a href="https://www.cdcxhl.com/xiyun.html" target="_blank">西云主机托管</a><a href="https://www.cdcxhl.com/gaiban/chengdu.html" target="_blank">成都网站改版</a><a href="https://www.cdcxhl.com/app.html" target="_blank">成都app开发</a><a href="https://www.cdcxhl.com/google.html" target="_blank">Google优化</a>            </div>
        </div>
    </div>
    <div class="foot">
        <div class="container">
            <div class="footNav">
                <h3>网站建设</h3>
                <a href="http://www.cxjianzhan.com/" target="_blank">网站建设公司</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">外贸营销网站建设</a><a href="http://m.cdcxhl.cn/qiye/" target="_blank">企业网站建设公司</a>            </div>
            <div class="footNav">
                <h3>服务器托管</h3>
                <a href="https://www.cdxwcx.com/jifang/guanghua.html" target="_blank">光华服务器托管</a><a href="https://www.cdcxhl.com/idc/xixin.html" target="_blank">西信服务器托管</a><a href="http://www.cdfuwuqi.com/" target="_blank">服务器托管机房</a>            </div>
            <div class="footNav">
                <h3>网站制作</h3>
                <a href="http://www.cxhlcq.com/zhizuo/" target="_blank">重庆网站制作</a><a href="http://www.dzwzjz.com/" target="_blank">达州网站制作</a><a href="http://www.cdxtjz.com/" target="_blank">网站制作</a>            </div>
            <div class="footNav">
                <h3>企业服务</h3>
                <a href="https://www.cdcxhl.com/service/dailijizhang.html" target="_blank">代理记账</a><a href="https://www.cdcxhl.com/service/gongsibiangeng.html" target="_blank">工商变更</a><a href="https://www.cdcxhl.com/link/" target="_blank">买友情链接</a>            </div>
            <div class="fr ecode">
                <div class="fl">
                    <img src="/Public/Home/img/ewm.jpg">
                    <p>关注企业微信</p>
                </div>
                <div class="fr slogan">
                    <p class="icon">
                        <a class="ph" href=""><i class="iconfont"></i></a>
                        <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a>
                    </p>
                    <p>
                        <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、
                        <a href="">营销型网站建设</a>、<a href="">网站建设</a>、
                        <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="bottom container">
            <p class="fl">
                版权所有:成都创新互联科技有限公司
                备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a>
                服务热线:028-86922220
            </p>
            <p class="fr">
                <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:
                <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a>
            </p>
        </div>
    </div>
</footer>
<!--在线咨询-->
<div class="fot">
    <ul>
        <li>
            <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank">
                <img src="/Public/Home/img/fot1.png" alt="">
                <p>在线咨询</p>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" target="_blank">
                <img src="/Public/Home/img/fot2.png" alt="">
                <p>拨打电话</p>
            </a>
        </li>
    </ul>
</div>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>