只有第一次上传的时候才能成功,第二次再上传就提示:java.lang.StringIndexOutOfBoundsException: length must be >= 0
-------------------------------------------------------------------private static final String CONTENT_TYPE = "text/html; charset=gb2312";
private ServletConfig s_config;
SmartUpload myUpload = new SmartUpload();
public void init(ServletConfig config) throws ServletException {
super.init(config);
this.s_config = config;
} public void destroy() {
} public UploadController() {
}
/** Processes requests for both HTTP
* <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException {
String next = PageDefine.PORTAL_ACTION_ERROR;
RequestHelper helper = new RequestHelper(request,response); try{
// Initialization
myUpload.initialize(s_config,request,response);
myUpload.upload();
// Files
// Save the file with the original name
// in a virtual path of the web server
if (myUpload.getRequest().getParameter("uploadfile")!=null){
myUpload.save(myUpload.getRequest().getParameter("uploadfile"));
}
System.out.println("<BR>");
}catch(Exception ex)
{
System.out.println(ex.toString());
}
} protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
}
-------------------------------------------------------------------private static final String CONTENT_TYPE = "text/html; charset=gb2312";
private ServletConfig s_config;
SmartUpload myUpload = new SmartUpload();
public void init(ServletConfig config) throws ServletException {
super.init(config);
this.s_config = config;
} public void destroy() {
} public UploadController() {
}
/** Processes requests for both HTTP
* <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException {
String next = PageDefine.PORTAL_ACTION_ERROR;
RequestHelper helper = new RequestHelper(request,response); try{
// Initialization
myUpload.initialize(s_config,request,response);
myUpload.upload();
// Files
// Save the file with the original name
// in a virtual path of the web server
if (myUpload.getRequest().getParameter("uploadfile")!=null){
myUpload.save(myUpload.getRequest().getParameter("uploadfile"));
}
System.out.println("<BR>");
}catch(Exception ex)
{
System.out.println(ex.toString());
}
} protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
}
初始化的位置调整到doPost或processRequest里看看?java.lang.StringIndexOutOfBoundsException: length must be >= 0
具体是哪一句出错?
在initialize前加SmartUpload myUpload = new SmartUpload();
重新建一个上传对象