FileUpload cannot be resolved

RootCoCo 2012-05-27 02:11:20
----------------这是ImageUploadHandler.jsp-------------------
<%@ page language="java" contentType="text/html; charset=gb2312"
import="java.util.*" import="java.io.*" import="mytest.*"pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>显示上传图片</title>
</head>
<body>
<%

String filePath = request.getSession().getServletContext().getRealPath("");//获取该项目的真实路径

out.println(filePath+"<br/>");

String photo=request.getParameter("imgUpload");//获取file控件里的路径(绝对路径)


int indexOfLine = photo.lastIndexOf("\\");

String fileName = photo.substring(indexOfLine+1,photo.length());//文件名(含后缀,不包含路径信息)

String destFilePathAndName = filePath+"\\image\\"+fileName;//要保存文件的路径

FileUpload.uploadImage(filePath+"\\image\\",photo,destFilePathAndName);//上传图片到目的路径

String relativeFilePath = ".\\image\\"+fileName;//用来显示图片的相对路径


out.println(photo+"<br/>");

out.println(destFilePathAndName+"<br/>");

%>
上传的图片:<img src="<%=relativeFilePath%>" width=100 height=112 border=0 alt="image display"/>

</body>
</html>
------------------这是mytest包里面的FileUpload类--------------------
package mytest;

import java.awt.image.BufferedImage;

import java.io.*;

import java.awt.Image;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGImageEncoder;


public class FileUpload

{

public static void uploadImage(String imgFolderPath,String srcFileName,String dstFileName) throws IOException

{

//判断文件夹image是否存在,若不存在则创建

File folder = new File(imgFolderPath);

System.out.println("function 'uploadFileTest2'-imgFolderPath'"+imgFolderPath);

if(!folder.exists())

{

folder.mkdir();

System.out.println("maked a folder!");

}


File _file = new File(srcFileName); //读入文件

Image src = javax.imageio.ImageIO.read(_file); //构造Image对象

int wideth=src.getWidth(null); //得到源图宽

int height=src.getHeight(null); //得到源图长

BufferedImage tag = new BufferedImage(wideth,height,BufferedImage.TYPE_INT_RGB);

tag.getGraphics().drawImage(src,0,0,wideth,height,null);

FileOutputStream out=new FileOutputStream(dstFileName); //输出到文件流

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

encoder.encode(tag); //JPEG编码

out.close();

System.out.println("function 'uploadFileTest2'-status:A Image File Saved!");

}

}


----------------------------------------
运行之后为什么出现如下错误呢?

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 25 in the jsp file: /ImageUploadHandler.jsp
FileUpload cannot be resolved
22:
23: String destFilePathAndName = filePath+"\\image\\"+fileName;//要保存文件的路径
24:
25: FileUpload.uploadImage(filePath+"\\image\\",photo,destFilePathAndName);//上传图片到目的路径
26:
27: String relativeFilePath = ".\\image\\"+fileName;//用来显示图片的相对路径
28:






...全文
463 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
RootCoCo 2012-05-27
  • 打赏
  • 举报
回复
呵呵,谢谢,不过问题解决了。
JavaMan 2012-05-27
  • 打赏
  • 举报
回复
FileUpload没有引入

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧