Try the JSP Smart Upload package, you have to download it,
then the following code is for uploading pictures:
Code:
<%@page contentType="text/html; charset=big5"%>
<%@page import="java.util.*,java.sql.*,java.net.*,java.io.*"%>
<%@page import="com.jspsmart.upload.*"%>
<%@page import="nesonline.*"%>
<html>
<head>
<title>file</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<link rel="stylesheet" type="text/css" href="all.css" />
</head>
<body>
<%
String login = (String) session.getAttribute("login");
if (login != null && login.equals("success")) {
%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
<%!FileUpload fileUpload = new FileUpload();%>
<%
String sevID = (String) session.getAttribute("sevID");
mySmartUpload.initialize(pageContext);
mySmartUpload.setMaxFileSize(1024 * 1024);
String path = (String) application.getRealPath("\\images\\empPhoto\\small") + "\\";
mySmartUpload.upload();
fileUpload.getQuery(sevID);
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing()) {
myFile.saveAs(path + fileUpload.getPhotoNo() + ".jpg");
myFile.saveAs(path + fileUpload.getPhotoNo() + ".gif");
}
}
response.setHeader("Refresh", "1;URL=pd.jsp");
%>
<%
} else {
out.println("<center><h1>±zÃÃ¥¼µn¤J¡I</h1></center>");
response.setHeader("Refresh", "2;URL=index.jsp");
}
%>
</body>
</html>