There is no javax. servlet package in JDK. The following program is used when it is used:
Import java. Io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class helloworld extends httpservlet {
Public void doget (httpservletrequest request, httpservletresponse response)
Throws ioexception, servletexception
{
Response. setcontenttype ("text/html ");
Printwriter out = response. getwriter ();
Out. println ("<HTML> ");
Out. println ("Out. println ("<title> Hello world! </Title> ");
Out. println ("Out. println ("<body> ");
Out. println ("Out. println ("</body> ");
Out. println ("}
}
When javac helloworld. Java is executed in the command line, the error code/helloworld. Java: 2:? is displayed :? Software Package? Javax. servlet? Does not exist?
? Import? Javax. servlet .*;?
? ^?
? D:/tomcat? 5.5/webapps/root/sl_exp/P90/helloworld. Java: 3 :? Software Package? Javax. servlet? Does not exist?
? Import? Javax. servlet. HTTP ;?
And so on.
How can this problem be solved?
The answer is: in Tomcat under D:/tomcat 6.0/lib find the servlet-api.jar file, copy a copy, and then extract, it will find that there is javax this file, this file contains the Servlet File. Copy the Servlet File to lib under JDK, for example, C:/program files/Java/jdk1.6.0 _ 12/lib, then you can recompile it.