加了上传图片的代码之后,中文存入数据库变成了问号?
我没加上传图片的代码之前,存入数据库的中文显示正常,可是加了上传图片的代码之后中文都变成了问号,究竟是怎么回事啊?
加了上传之后的代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,
java.sql.*,com.jspsmart.upload.*,java.util.*,cn.oof.database.*,cn.oof.house.*" errorPage="" %>
<jsp:useBean id="connBean" scope="page" class="beans.connDB"/>
<jsp:useBean id="chStr" class="beans.chStr" scope="page" />
<%!
String filename="";
int old_h=0;
int old_w=0;
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=4000000;
String fileName2="";
String ext="";
String testvar="";
String url="web/bbs/uploadfile/images/";
%>
---------上传图片代码
<%
mySmartUpload.initialize(pageContext);
try
mySmartUpload.setAllowedFilesList("jpg,gif");
mySmartUpload.upload();
}
catch (Exception e){}
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
try{
为了方便看省略一部分代码......................................
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);
BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
FileOutputStream newimage=new FileOutputStream(newurl);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newimage.close();
}
}
}
catch (Exception e)
{
e.toString();
}
%>
----------插入数据库
<%
request.setCharacterEncoding("GBK");
com.jspsmart.upload.Request req = mySmartUpload.getRequest();
int UID=Integer.parseInt(req.getParameter("UID"));
String title=chStr.chStr(req.getParameter("title"));
String face="face/"+chStr.chStr(req.getParameter("face"))+".gif";
String content=chStr.chStr(req.getParameter("content"));
String image_max="uploadfile/images/"+filename+"."+ext;
String image_min="uploadfile/images/"+filename+"_min."+ext;
-----------省略............................................
%>
title 和 content 都是问号
face是文件路径
到底怎么回事?????????
加了上传之后的代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,
java.sql.*,com.jspsmart.upload.*,java.util.*,cn.oof.database.*,cn.oof.house.*" errorPage="" %>
<jsp:useBean id="connBean" scope="page" class="beans.connDB"/>
<jsp:useBean id="chStr" class="beans.chStr" scope="page" />
<%!
String filename="";
int old_h=0;
int old_w=0;
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=4000000;
String fileName2="";
String ext="";
String testvar="";
String url="web/bbs/uploadfile/images/";
%>
---------上传图片代码
<%
mySmartUpload.initialize(pageContext);
try
mySmartUpload.setAllowedFilesList("jpg,gif");
mySmartUpload.upload();
}
catch (Exception e){}
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
try{
为了方便看省略一部分代码......................................
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);
BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
FileOutputStream newimage=new FileOutputStream(newurl);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newimage.close();
}
}
}
catch (Exception e)
{
e.toString();
}
%>
----------插入数据库
<%
request.setCharacterEncoding("GBK");
com.jspsmart.upload.Request req = mySmartUpload.getRequest();
int UID=Integer.parseInt(req.getParameter("UID"));
String title=chStr.chStr(req.getParameter("title"));
String face="face/"+chStr.chStr(req.getParameter("face"))+".gif";
String content=chStr.chStr(req.getParameter("content"));
String image_max="uploadfile/images/"+filename+"."+ext;
String image_min="uploadfile/images/"+filename+"_min."+ext;
-----------省略............................................
%>
title 和 content 都是问号
face是文件路径
到底怎么回事?????????
...全文
相关推荐
java实现上传图片存入到数据库
总之,Java实现图片上传并存储到数据库涉及文件上传、文件处理、数据库操作等多个环节,需要综合运用多种技术。通过合理的代码设计和规范的数据库操作,可以构建出稳定可靠的图片上传系统。
基于Spark的新闻大数据实时分析系统:从数据洪流到可视化洞察
实时数据处理是应对信息爆炸时代的关键技术,其核心在于对高速产生的数据流进行即时处理与分析。Apache Spark作为主流的大数据计算框架,其Structured Streaming模块通过微批处理模型,提供了事件时间处理、端到端恰好一次语义等能力,有效解决了流式计算中的乱序数据与状态管理难题。在工程实践中,结合Kafka作为高吞吐消息队列,以及ClickHouse这类列式OLAP数据库,能够构建出高性价比的实时数据处理管道。这种技术组合特别适用于新闻舆情分析、社交媒体监控等场景,能够从非结构化的文本洪流中
将图片存入mysql数据库中
**当用户上传图片时,你需要在后端代码中处理图片数据。
PHP将图片存入数据库代码
在PHP开发中,将图片存入数据库是一种常见的需求,尤其在处理用户上传的头像、商品图片等场景。本文将详细讲解如何实现这一功能,并提供一个基础的代码示例。首先,我们需要理解为什么要在数据库中存储图片。
通过二进制数据流的方式,读写图片,把图片存入数据库
本主题主要探讨如何利用二进制数据流来读取、写入图片,并将其安全地存入数据库,以及如何从数据库中读取并显示这些图片。


Web 开发
