📄 servletupload.java
字号:
package com.upload.ajax;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.File;
import com.jspsmart.upload.SmartUpload;
public class ServletUpload extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
private ServletConfig config;
final public void init(ServletConfig config)throws ServletException{
this.config=config;
}
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<BODY BGCOLOR='white'>");
out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
out.println("<HR>");
//变量定义
int count =0;
SmartUpload mySmartUpload = new SmartUpload();
try{
mySmartUpload.initialize(config,request,response);
mySmartUpload.upload();
for(int i=0;i<mySmartUpload.getFiles().getCount();i++){
File myFile = mySmartUpload.getFiles().getFile(i);
String fileName = myFile.getFileName();
System.out.println("fileName===="+fileName);
count = mySmartUpload.save("/upload");
}
out.println(count+" file uploaded.");
}catch(Exception e){
out.println("Unable to upload the file.<br>");
out.println("Error: "+e.toString());
}
out.println("</BODY>");
out.println("</HTML>");
}
@Override
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(arg0, arg1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -