java 图片保存到MySQL数据库

这篇博客介绍如何使用Java处理HTML页面中的图片上传,通过Ajax方式将图片保存到MySQL数据库。当用户没有上传头像时,系统会显示默认图片。在控制器中,图片被读取、缩放并转换为字节数组存入数据库。同时,提供了一个从数据库读取用户头像并在页面上展示的方法。
摘要由CSDN通过智能技术生成

html 页面

先判断数据库中是否有头像,如果有则显示出来(selectUserHeadIcon.do)

没有这默认显示一个图片

<div id="MyheadIcon" class="flag" style="display: none;">
                            <div class="title">
                                我的头像
                            </div>
                            <div style="width: 300px;">
                                <div style="margin-top: 40px; text-align: center;">
                                    <div class="file" style="width: 100px; height: 100px;" id="dvFile" >
                                        <c:if test="${not empty icons}">
                                            <img id="uploadPreview" style="width: 100px; height: 100px; border-radius: 100px;" src="${ctx}/selectUserHeadIcon.do" alt="User Image">
                                        </c:if>
                                        <c:if test="${empty icons}">
                                            <img id="uploadPreview" style="width: 100px; height:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值