SmartUpload su = new SmartUpload();
su.initialize(pageContext);
pageContext变量找不到,并且不能用new PageContext()定义该变量,如何解决呢?
在action中可以这样得到pageContetext对象
import javax.servlet.jsp.JspFactory;
import com.jspsmart.upload.SmartUpload;
SmartUpload su = new SmartUpload();
JspFactory _jspxFactory = JspFactory.getDefaultFactory();
javax.servlet.jsp.PageContext pageContext =
_jspxFactory.getPageContext(
this.getServlet(),
request,
response,
null,
true,
8192,true);
su.initialize(pageContext);
servlet中
public class servletUpload extends HttpServlet
{
private ServletConfig config;
public void destroy() { }
public void doGet(HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse)
throws ServletException, IOException { }
protected void doPost(HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
SmartUpload smartupload = new SmartUpload();
try
{
smartupload.initialize(getServletConfig(), httpservletrequest, httpservletresponse);
smartupload.upload();
......
}
catch(Exception exception)
{
}
}
public final ServletConfig getServletConfig() { return config; }
public final void init(ServletConfig servletconfig) throws ServletException
{
config = servletconfig;
}
本文介绍了解决在使用SmartUpload组件时遇到的pageContext变量找不到的问题。提供了两种解决方案:一种是在action中通过JspFactory获取pageContext对象;另一种是在servlet中通过getServletConfig()方法初始化SmartUpload对象。


被折叠的 条评论
为什么被折叠?



