servlet用jspsmart上传的时候获得pageContext对象
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.jspsmart.upload.*;
import javax.servlet.jsp.*;
public class Hello extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
SmartUpload su = new SmartUpload();
try{
JspFactory _jspxFactory = null;
PageContext pageContext = null;
_jspxFactory = JspFactory.getDefaultFactory();
pageContext = _jspxFactory.getPageContext(this,request,response,"",true,8192,true);
su.initialize(pageContext);
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
file.saveAs("upload/"+file.getFileName());
pageContext.forward("index.htm");
}catch(Exception e){
}
其实在jsp中有的对象,在servlet不知道怎么用的话可以先编译jsp,然后在服务器的work目录中找到jsp所对应的servlet文件,找到相应的代码就可以了,因为jsp最终也会被编译成servlet文件。