当前位置: 代码迷 >> Java Web开发 >> 无法实现文件的下传,老报错?求大神帮帮忙解决一上,包和配置文件都配置好了
  详细解决方案

无法实现文件的下传,老报错?求大神帮帮忙解决一上,包和配置文件都配置好了

热度:5481   发布时间:2013-02-25 21:14:01.0
无法实现文件的上传,老报错??求大神帮帮忙解决一下,包和配置文件都配置好了
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.servlet.ServletConfig;

import com.jspsmart.upload.File;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;


import dao.NewsDao;
import dao.impl.NewsDaoimpl;

import bean.News;

public class AddServlet extends HttpServlet {


protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

//PrintWriter out = response.getWriter();

//out.println("Hello");


SmartUpload su=new SmartUpload();

Request req = null;
try{
su.initialize(this.getServletConfig(),request,response);
su.setAllowedFilesList("jpg,gif,doc");
su.upload();
File file=su.getFiles().getFile(0);
String filepath="upload//";
filepath+=file.getFieldName();
file.saveAs(filepath,SmartUpload.SAVE_VIRTUAL );

req = su.getRequest();


}catch(Exception e){
System.out.println(e.getMessage());
}


//request.setCharacterEncoding("utf-8");
News news=new News();
NewsDao nDao=new NewsDaoimpl();
Integer Tnid=Integer.parseInt(req.getParameter("ntid"));
String ntitle=req.getParameter("ntitle");
String nauthor=req.getParameter("nauthor");
String nsummary=req.getParameter("nsummary");
String ncontent=req.getParameter("ncontent");
String path=req.getParameter("file");
news.setNtid(Tnid);
news.setNtitle(ntitle);
news.setNauthor(nauthor);
news.setNsummary(nsummary);
news.setNcontent(ncontent);
news.setNpicpath(path);
try {
if(nDao.addNews(news)>0){
System.out.println("<Script> alert('添加成功!');location='../admin.jsp' </Script>");
}else{
response.sendRedirect("../news_add.jsp");
}
} catch (Exception e) {

e.printStackTrace();
}
}
}


控制台输出的报错提示:
2012-5-28 17:50:57 org.apache.catalina.core.AprLifecycleListener init
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Users\MRqiang\AppData\Local\Genuitec\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;D:\Users\MRqiang\AppData\Local\Genuitec\Common\plugins\com.genuitec.eclipse.easie.tomcat.myeclipse_8.6.0.me201007231647\tomcat\bin
2012-5-28 17:50:57 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2012-5-28 17:50:57 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1962 ms
2012-5-28 17:50:57 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-5-28 17:50:57 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.13
2012-5-28 17:51:00 com.sun.faces.config.ConfigureListener$WebXmlProcessor scanForFacesServlet
警告: Unable to process deployment descriptor for context 'null'
2012-5-28 17:51:00 com.sun.faces.config.ConfigureListener contextInitialized
信息: Initializing Sun's JavaServer Faces implementation (1.2_04-b07-FCS) for context '/Demo'
2012-5-28 17:51:02 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-5-28 17:51:02 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2012-5-28 17:51:02 org.apache.jk.server.JkMain start
  相关解决方案