如何把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 ++; } }
%>
我试了两天,都没试成,就是这一句说什么错误,没辙,请大家帮忙!
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 ++; } }
%>
解决方案 »
- 在html中,不用<script src="xxx.js"> 用其他办法,也能调用xxx.js中的方法吗?
- Java把文件打成包tar包!网上试了好几种方法,都不支持中文,求解啊!
- GPS+GIS获取地图数据后标记应采用的技术
- 十万火急,org.apache.tools.zip 解压错误
- 谁知道 新浪 的新闻页面是怎么做的!????? www.sina.com.cn
- JS与JSP交互问题
- 各位大哥哥 大姐姐 谢谢帮我解决下 新手. .实在看不懂...
- 请问 " 用尽的resultSet " 是什么意思啊??
- jsp如何防止由于用户刷新网页引起的重复计算错误?
- 为什么需要释放jdbc资源
- 怎样将远程用户的dbf文件中的数据导入到数据库表中?
- 怎样才能把中文保存到数据库里面
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;
这一句是什么意思?
在servlet中定义config
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
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() {
}
}
用import找不到此包
用import找不到此包
import javax.servlet.jsp.PageContext;///////找不到
import javax.servlet.jsp.JspFactory;///////找不到
upload_jsp.java
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);
...
}
...