java - Servlet exception when trying to open it -
i programmed servlet should print out 'hello world', not working correctly.
i start tomcat running startup.sh
in /usr/share/tomcat8/bin/startup.sh
, program in folder /usr/share/tomcat8/webapps/hello/web-inf/classes/helloworld.class
.
this web.xml:
<servlet> <servlet-name>helloworld</servlet-name> <servlet-class>helloworld</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloworld</servlet-name> <url-pattern>/helloworld</url-pattern> </servlet-mapping>
this source code:
import java.io.*; import javax.servlet.http.*; import javax.servlet.servletexception; public class helloworld extends httpservlet { static final long serialversionuid = 42l; public void doget(httpservletrequest request, httpservletresponse response) throws ioexception, servletexception { response.setcontenttype("text/html"); printwriter out = response.getwriter(); out.println("<html>"); out.println("<head>"); out.println("\t<title>test</title>"); out.println("</head>"); out.println("<body>"); out.println("<b>hello world!</b>"); out.println("</body>"); out.println("</html>"); } }
i compile following command:
javac -classpath %j2ee_home%\lib\j2ee.jar -classpath ../../../../lib/servlet-api.jar helloworld.java
there no compiling errors, when visit ipaddress:8080/hello/helloworld
following errorcode:
exception java.lang.nullpointerexception org.apache.catalina.loader.webappclassloaderbase.binarynametopath(webappclassloaderbase.java:2562) org.apache.catalina.loader.webappclassloaderbase.findloadedclass0(webappclassloaderbase.java:2730) org.apache.catalina.loader.webappclassloaderbase.loadclass(webappclassloaderbase.java:1208) org.apache.catalina.loader.webappclassloaderbase.loadclass(webappclassloaderbase.java:1166) org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:490) org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:616) org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:528) org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1099) org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:670) org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1520) org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1476) java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) java.lang.thread.run(thread.java:745)
Comments
Post a Comment