cmd下运行javac java

来源:百度知道 编辑:UC知道 时间:2024/05/18 05:25:47
java文件:
import javax.servlet.ServletException;
import java.io.*;
import javax.servlet.http.*;

public class SimpleHello extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter out=resp.getWriter();
out.println("Hello World");
out.close();
}
}
javac通过
java时:
Exception in thread "main" java.lang.NoSuchMethodError: main
Error: A JNI error has occurred, please check your installation and try again

大哥!这是一个servlet,不是一个普通的java类,是要在web服务器或者web容器中才能运行的!!!
ps:该错误的意思是,SimpleHello这个类里没有main方法!
HelloWorld是这样写的:
public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello World!!");
}

}