读书人

FileUpload cannot be resolved,该怎么

发布时间: 2013-09-11 18:34:25 作者: rapoo

FileUpload cannot be resolved
----------------这是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:








[解决办法]
FileUpload没有引入
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

读书人网 >J2EE开发

热点推荐