package com.control.upfile;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 com.jspsmart.upload.SmartFile;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;
import com.model.UpFileDao;import com.pojo.UpFile;
import com.pojo.Student;
import com.tool.MyFormat;public class UploadServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=gb2312");
Student student=(Student)request.getSession().getAttribute("student");
int stuid=student.getStudentid();
System.out.println(stuid);

SmartUpload su=new SmartUpload();
    su.initialize(this.getServletConfig(), request, response);
    try {
su.upload();
int count=su.save("/files");
for(int i=0;i<su.getFiles().getCount();i++){
SmartFile file=su.getFiles().getFile(i);
if(file.isMissing())
continue;
String filename=file.getFileName();
String url=this.getServletContext().getRealPath("/files/");
String urls=url+"\\"+filename;
System.out.println("url="+urls);
String uptime=MyFormat.stdDateTimeNow();
System.out.println("time="+uptime);
UpFile upfile=new UpFile();
upfile.setFilename(filename);
upfile.setUrl(urls);
upfile.setStudentid(stuid);
upfile.setUptime(uptime);
UpFileDao upfiledao=new UpFileDao();
upfiledao.insertOne(upfile);
}

} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.getRequestDispatcher("ShowFileServlet").forward(request, response);
}}
运行过后总是出现一下错误:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
com.control.upfile.UploadServlet.service(UploadServlet.java:28)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.