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 preven