servlet上传文件无法解析 pageContext
index.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="selectfile" enctype="multipart/form-data" method="post" action="logon/Fileup">
<p>文件名称:
<input type="file" name="ulfile" size="20" maxlength="80"><br>
</p>
<p>上传路径:
<input type="text" name="PATH" size="30" maxlength="50"><br>
</p>
<p>附加内容:
<input type="text" name="other" size="30" maxlength="50"><br>
</p>
<p>
<input type="submit" value="上传">
<input type="reset" value="清除">
</p>
</form>
</body>
</html>
Fileup.java*******************************************************
package judge;
import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.*;
import com.jspsmart.upload.*;
public class Fileup extends HttpServlet {
private ServletConfig config;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
SmartUpload su= new SmartUpload();
su.initialize(config,request,response);
int count=0;
SmartUpload mySmartUpload = new SmartUpload();
try {
mySmartUpload.initialize(config,request,response);
mySmartUpload.upload();
com.jspsmart.upload.File f1 = mySmartUpload.getFiles().getFile(0);
String name = f1.getFileName();
count = mySmartUpload.save(mySmartUpload.getRequest().getParameter("PATH"));
//other为form表单提交过来的
String other=mySmartUpload.getRequest().getParameter("other"); //这里可以对other进行处理
//request.getParameter("PATH");request.gerParameter("other");
// 显示处理结果
out.println(count + " file uploaded.");
} catch (Exception e){
out.println("Unable to upload the file.<br>");
out.println("Error : " + e.toString());
}
out.println("</BODY>");
out.println("</HTML>");
}
}
}
}
}
错误内容****************************
严重: Servlet.service() for servlet Fileup threw exception
java.lang.Error: 无法解析的编译问题:
无法解析 pageContext
at judge.Fileup.doPost(Fileup.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Thread.java:619)