您的位置:程序门 -> java -> j2ee / ejb / jms



用jspsmartupload组件上传初始化出错,高分求解


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


用jspsmartupload组件上传初始化出错,高分求解
发表于:2007-06-06 10:32:39 楼主
在servlet中
pagecontext   pagecontext   =   null;
smartupload   su   =   new   smartupload();
    su.initialize(pagecontext);//上传初始化
到这一步会给出这样的错误:
standardwrappervalve[file_upload_download]:   servlet.service()   for   servlet   file_upload_download   threw   exception

java.lang.nullpointerexception

java.lang.nullpointerexception

at   com.jspsmart.upload.smartupload.initialize(smartupload.java:136)
发表于:2007-06-06 10:39:121楼 得分:0
空指针异常。。。
你把pagecontext初始化的值为null,然后再对这个值进行操作,就会产生空指针异常啦。。。
帮顶。。。
发表于:2007-06-06 10:57:132楼 得分:0
给你段代码自己分析
import   java.io.*;
import   java.util.*;
import   javax.servlet.*;
import   javax.servlet.http.*;
import   com.jspsmart.upload.*;

public   class   servletupload   extends   httpservlet   {

private   servletconfig   config;
/**
*   init   the   servlet
*/
final   public   void   init(servletconfig   config)   throws   servletexception   {
this.config   =   config;
}

final   public   servletconfig   getservletconfig()   {
return   config;
}
/**
*   handles   get   requests
*/
public   void   doget(httpservletrequest   request,   httpservletresponse   response)   throws   servletexception,   ioexception   {

printwriter   out   =   response.getwriter();
out.println( " <html> ");
out.println( " <body   bgcolor= 'white '> ");
out.println( " <h1> jspsmartupload   :   servlet   sample </h1> ");
out.println( " <hr> <br> ");
out.println( "the   method   of   the   html   form   must   be   post. ");
out.println( " </body> ");
out.println( " </html> ");
}

/**
*   handles   post   requests
*/
protected   void   dopost(httpservletrequest   request,   httpservletresponse   response)   throws   servletexception,   ioexception   {

printwriter   out   =   response.getwriter();
out.println( " <html> ");
out.println( " <body   bgcolor= 'white '> ");
out.println( " <h1> jspsmartupload   :   servlet   sample </h1> ");
out.println( " <hr> ");

//   variables
int   count=0;
smartupload   mysmartupload   =   new   smartupload();

try   {
//   initialization
mysmartupload.initialize(config,request,response);

//   upload
mysmartupload.upload();

//   save   the   file   with   the   original   name
//   in   a   virtual   path   of   the   web   server
count   =   mysmartupload.save(mysmartupload.getrequest().getparameter( "path "));

//   display   the   result
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> ");
                    }
/**
*   destroy   the   servlet
*/
public   void     destroy   ()   {
}

}  


注意前面的servletconfig   config;
发表于:2007-06-22 15:34:373楼 得分:0
jf
发表于:2007-06-22 17:53:194楼 得分:0
开源少林寺首次面向全国开门收徒.
javaee一线开发人员的坚强后盾.提供全程的技术支持.拥有独立的千g服务器.
飞速加入吧.
qq群:21464991
发表于:2007-07-04 16:36:465楼 得分:0
该回复于2007-12-28 12:03:54被管理员或版主删除


快速检索

最新资讯
热门点击