如何把JSPsmartUPload的upload.jps页面改为servlet?
我试了两天,都没试成,就是这一句说什么错误,没辙,请大家帮忙!
mySmartUpload.initialize(pageContext);就是这句出错
<%@ page contentType="text/html; charset=gb2312" language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="db" scope="page" class="my.dcsky.execSql"/>
<%
// Variables
int count=0;         // Initialization
mySmartUpload.initialize(pageContext); // Upload
mySmartUpload.upload();
//mySmartUpload.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// Select each file
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){ // Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i); // Save it only if this file exists
if (!myFile.isMissing()) { // Save the files with its original names in a virtual path of the web server       
myFile.saveAs("logo/" + myFile.getFileName());

out.println("图片上传成功...");
count ++; } }

%>

解决方案 »

  1.   

    SmartUpload su = new SmartUpload();
                PageContext pageContext = JspFactory.getDefaultFactory().
                                          getPageContext(this, request, response, null, true,
                        8192, true);
                su.initialize(pageContext);
                su.upload();
    ------------------
    import javax.servlet.jsp.PageContext;
    import javax.servlet.jsp.JspFactory;
      

  2.   

    好的,谢谢funcreal(为中华之崛起而编程)我回去试试
      

  3.   

    getPageContext(this, request, response, null, true,8192, true);
    这一句是什么意思?
      

  4.   

    你可以这样su.initialize(config, request, response);
    在servlet中定义config
    private ServletConfig config;
    final public void init(ServletConfig config) throws ServletException {
    this.config = config;
    }
      

  5.   

    import javax.servlet.jsp.PageContext;
    import javax.servlet.jsp.JspFactory;我改了,这两个包找不到啊,奇怪?帖出来:
    package my.sky;import javax.servlet.jsp.PageContext;///////找不到
    import javax.servlet.jsp.JspFactory;///////找不到
    import com.jspsmart.upload.SmartUpload;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;public class dcskyManagerUpSmallProspectus extends HttpServlet{

    protected void service(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException{
    request.setCharacterEncoding("gbk");
    response.setCharacterEncoding("gbk");
    PrintWriter out=response.getWriter();

    int count=0; 
        SmartUpload su = new SmartUpload();
    PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true,8192, true);
    su.initialize(pageContext);
    su.upload();

         for (int i=0;i<su.getFiles().getCount();i++){ // Retreive the current file
    com.jspsmart.upload.File myFile = su.getFiles().getFile(i); // Save it only if this file exists
    if (!myFile.isMissing()) { // Save the files with its original names in a virtual path of the web server       
    myFile.saveAs("/test/" + myFile.getFileName());
    ......//省略
    db.executeUpdate();
    out.println("图片上传成功...");
    count ++; } }

       } 
        public void destory() {
      }
    }
      

  6.   

    如何引用啊jsp-api.jar!!!!!!!!!!!!!!!!!!!!!!我越来越晕了!!!!
    用import找不到此包
      

  7.   

    如何引用啊jsp-api.jar!!!!!!!!!!!!!!!!!!!!!!我越来越晕了!!!!
    用import找不到此包
      

  8.   

    那为什么
    import javax.servlet.jsp.PageContext;///////找不到
    import javax.servlet.jsp.JspFactory;///////找不到
      

  9.   

    在硬盘上search:
    upload_jsp.java
      

  10.   

    你把servlet-api.jar加入了项目的路径了吗?不加入是找不到的......你是用eclipse还是其它的开发工具?
      

  11.   

    晕,利用jbuilder 或者eclipse起个工程编译就行
      

  12.   

    RainRainbow() 已经讲得非常清楚了!!private ServletConfig config;
    public void init(ServletConfig config) throws ServletException 
    {
        this.config = config;
    }public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    {
        SmartUpload su = new SmartUpload();
        su.initialize(config, request, response);
        ...
    }
    ...