当前位置: 技术问答>java相关
编了一段很小的程序,报了一个很低级的错误(编译通过)
来源: 互联网 发布时间:2015-04-23
本文导语: ////////一个servlet package upload; import java.io.*; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.*; //import iecworl.jutil.Common; public class upload { private DataInputStream in=null; //private ByteArrayInput...
////////一个servlet
package upload;
import java.io.*;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
//import iecworl.jutil.Common;
public class upload
{
private DataInputStream in=null;
//private ByteArrayInputStream bin=null;
private FileOutputStream fileWrite=null;
private String contentType;
private String fileContent="";
private int formDataLength;
private static final int SMALL_MAX_SIZE=102400;
private static final int BIG_MAX_SIZE=512000;
public void doPost(
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
{
java.io.PrintWriter out = new PrintWriter(response.getWriter());
contentType = request.getContentType();
if (contentType==null || contentType.toLowerCase().indexOf("multipart/form-data")==-1)
{
out.println("mime类型不正确!");
}
formDataLength = request.getContentLength();
in = new DataInputStream(request.getInputStream());
byte dataBytes[] = new byte[formDataLength];
//bin = new ByteArrayInputStream(dataBytes);
out.println(String.valueOf(formDataLength));
}
}
---------------
编译通过,
在浏览器里,报错
500 Servlet Exception
javax.servlet.ServletException: `upload.upload' must implement javax.servlet.Servlet
at com.caucho.server.http.Application.instantiateServlet(Application.java:2842)
at com.caucho.server.http.Application.createServlet(Application.java:2753)
at com.caucho.server.http.Application.loadServlet(Application.java:2711)
at com.caucho.server.http.Application.getFilterChainServlet(Application.java:2478)
at com.caucho.server.http.Application.buildFilterChain(Application.java:2445)
at com.caucho.server.http.Invocation.service(Invocation.java:276)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
at com.caucho.server.http.ServletServer.serviceTop(ServletServer.java:847)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:213)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
--------------------------------------------------------------------------------
Resin 2.0.4 (built Thu Nov 15 17:56:24 PST 2001)
package upload;
import java.io.*;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
//import iecworl.jutil.Common;
public class upload
{
private DataInputStream in=null;
//private ByteArrayInputStream bin=null;
private FileOutputStream fileWrite=null;
private String contentType;
private String fileContent="";
private int formDataLength;
private static final int SMALL_MAX_SIZE=102400;
private static final int BIG_MAX_SIZE=512000;
public void doPost(
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
{
java.io.PrintWriter out = new PrintWriter(response.getWriter());
contentType = request.getContentType();
if (contentType==null || contentType.toLowerCase().indexOf("multipart/form-data")==-1)
{
out.println("mime类型不正确!");
}
formDataLength = request.getContentLength();
in = new DataInputStream(request.getInputStream());
byte dataBytes[] = new byte[formDataLength];
//bin = new ByteArrayInputStream(dataBytes);
out.println(String.valueOf(formDataLength));
}
}
---------------
编译通过,
在浏览器里,报错
500 Servlet Exception
javax.servlet.ServletException: `upload.upload' must implement javax.servlet.Servlet
at com.caucho.server.http.Application.instantiateServlet(Application.java:2842)
at com.caucho.server.http.Application.createServlet(Application.java:2753)
at com.caucho.server.http.Application.loadServlet(Application.java:2711)
at com.caucho.server.http.Application.getFilterChainServlet(Application.java:2478)
at com.caucho.server.http.Application.buildFilterChain(Application.java:2445)
at com.caucho.server.http.Invocation.service(Invocation.java:276)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
at com.caucho.server.http.ServletServer.serviceTop(ServletServer.java:847)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:213)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
--------------------------------------------------------------------------------
Resin 2.0.4 (built Thu Nov 15 17:56:24 PST 2001)
|
public class upload
{
.
.
.
}
if class upload is a servlet,
you must extends javax.servlet.http.HttpServlet or it's subclass
{
.
.
.
}
if class upload is a servlet,
you must extends javax.servlet.http.HttpServlet or it's subclass