如何用组件传图片到数据库和服务器中去,然后在从数据库中把这张图片取值到jsp页面中去但有可能不正确急急急就差他了
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.entity.Goods"%>
<%@page import="com.biz.impl.GoodsBizimpl"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="com.jspsmart.upload.Files"%>
<%
//创建一个上传的组件
SmartUpload su = new SmartUpload();
//初始化SmartUpload对象(重)
su.initialize(pageContext); //pageContext上下文 -- application
com.jspsmart.upload.File file = null; //非IO包下的File类
com.jspsmart.upload.Request req = null;
//定义允许上传类型
String allowed = "gif,jpg,png,txt";
//定义不许上传类型
String denied = "jsp,asp,php,aspx,html,htm,exe,bat";
//文件上传类型,二选一,一般会选择允许上传类型
//定义上传文件大小
int file_size = 5*1024*1024; //不能超过2M
String exceptionMsg = null; //异常信息对象
try {
//定义允许上传文件类型
su.setAllowedFilesList(allowed);
//不允许上传文件类型
su.setDeniedFilesList(denied);
//单个文件最大限制
su.setMaxFileSize(file_size);
//设置上传对象的编码
su.setCharset("utf-8"); //GBK GB2312
//执行上传(重)
su.upload();
String filepath = null; //路径
//su.getFiles()获得所有文件对象
Files f= su.getFiles();
//循环读取文件对象
for(int i=0; i<f.getCount(); i++){
//取文件对象
file=f.getFile(i);
//判断是否有对象
if(!file.isMissing()){
//设置文件在服务器的保存位置
filepath = "upload\\"; //保存到一个upload的文件夹下
//filepath += file.getFileName(); //拼接文件名字
filepath += System.currentTimeMillis()+ file.getFileName().substring( file.getFileName().lastIndexOf("."));
//文件另存为
file.setCharset("utf-8");
//保存(重)
file.saveAs(filepath, SmartUpload.SAVE_VIRTUAL); //上传模式
}
}
} catch (Exception e) {
exceptionMsg = e.getMessage();
e.printStackTrace();
}
//转码
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
//获取传过来的i的值
String productName=request.getParameter("productName");
int parentId=Integer.parseInt(request.getParameter("parentId"));
String photo=request.getParameter("photo");
int jiage=Integer.parseInt( request.getParameter("jiage"));
int kuchun=Integer.parseInt( request.getParameter("kuchun"));
String tiaoma=request.getParameter("tiaoma");
//out.print(productName+" "+ parentId+" "+ photo+" "+ jiage +" "+kuchun +" "+tiaoma);
//调dao 方法
Goods g=new Goods(productName,parentId,photo,jiage,kuchun,tiaoma);
int n=new GoodsBizimpl().getCr(g);
if(n>0){
out.print("添加成功");
}else{
out.print("添加失败");
}
%>
获取那个值不会,一直报错