上傳文件在Java中我使用javazoom上傳使用servlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
PrintWriter out = null;
JOptionPane.showMessageDialog(null, "Lets do this");
try {
response.setContentType("text/html;charset=UTF-8");
try {
MultipartFormDataRequest dataRequest = new MultipartFormDataRequest(request);
//get uploaded files
Hashtable files = dataRequest.getFiles();
if (!files.isEmpty()) {
UploadFile uploadFile = (UploadFile) files.get("filename");
byte[] bytes = uploadFile.getData();
String s = new String(bytes);
的文件總是來爲空。 請幫忙嗎?
我然後試圖與Apache通用FileUpload這樣做:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
PrintWriter out = null;
try {
response.setContentType("text/html;charset=UTF-8");
//MultipartFormDataRequest dataRequest = new MultipartFormDataRequest(request);
//get uploaded files
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
List files = null;
try {
files = upload.parseRequest(request);
} catch (FileUploadException ex) {
Logger.getLogger(ProcessUploadItem.class.getName()).log(Level.SEVERE, null, ex);
}
,並未能在files = upload.parseRequest(request);
任何指針?
對不起和謝謝:)
請注意標記問題時的提示提示。名稱後面的數字小於10的任何標籤可能都是錯誤的。避免創建新標籤。 – 2009-06-05 14:41:01
啊thnx ...我會記住這一點 – Lilz 2009-06-07 13:36:12