当前页面: 开发资料首页 → JSP 专题 → 如何把JSPsmartUPload的upload.jps页面改为servlet?
如何把JSPsmartUPload的upload.jps页面改为servlet?
摘要: 如何把JSPsmartUPload的upload.jps页面改为servlet?
如何把JSPsmartUPload的upload.jps页面改为servlet?
我试了两天,都没试成,就是这一句说什么错误,没辙,请大家帮忙!
mySmartUpload.initialize(pageContext);就是这句出错
<%@ page contentType="text/html; charset=gb2312" language="java" import="com.jspsmart.upload.*"%>
<%
// 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
// 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 ++;
}
}
%>
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;
好的,谢谢funcreal(为中华之崛起而编程)
我回去试试
getPageContext(this, request, response, null, true,8192, true);
这一句是什么意思?
DDDDDDDDDDDDDDDDDDDDDDDDDDDDD
你可以这样su.initialize(config, request, response);
在servlet中定义config
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
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
// 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() {
}
}
jsp-api.jar这里面有的。
如何引用啊jsp-api.jar!!!!!!!!!!!!!!!!!!!!!!我越来越晕了!!!!
用import找不到此包
顶
如何引用啊jsp-api.jar!!!!!!!!!!!!!!!!!!!!!!我越来越晕了!!!!
用import找不到此包
是:servlet-api.jar包...
/tomcat/common/lib/servlet-api.jar
那为什么
import javax.servlet.jsp.PageContext;///////找不到
import javax.servlet.jsp.JspFactory;///////找不到
在硬盘上search:
upload_jsp.java
救命,和位大人,我的问题没解决,仍是找不到类,如上
你把servlet-api.jar加入了项目的路径了吗?不加入是找不到的......你是用eclipse还是其它的开发工具?
加入了,我用的是JCreator
DDD
晕,利用jbuilder 或者eclipse起个工程编译就行
dddddddddddd
帮忙啊,高手们!都在忙什么?
帮忙啊,高手们!都在忙什么?
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);
...
}
...
顶!!!!