java.servlet.* cannot import, but javax.servlet.* ok???
zhangzh
Greenhorn
Joined: Sep 22, 2000
Posts: 10
posted
0
part of the source code is as follows import java.io.*; import java.servlet.*; import javax.servlet.*; ... i set my classpath correctly, the compiler reported that java.servlet.* not found in import, but javax.servlet.* is ok. any idea??? Thanks! zhangzh
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
I may be wrong but I don't think java.servlet package exists. Vijay
zhangzh
Greenhorn
Joined: Sep 22, 2000
Posts: 10
posted
0
thank you, i remarked "import java.servlet.*;" the compiler says Superclass HttpServlet does exists, "impot javax.servlet.*;" is not causing any error.
maha anna
Ranch Hand
Joined: Jan 31, 2000
Posts: 1467
posted
0
zhangzh, Vijay is correct. All servlet related APIs are kept in the java 'extented' package. So is the 'x' in the package name. 'java.servlet' package is not there. May be you are mistaken with the 2 imports we generally put at the top of any servlet source file. They are import javax.servlet.*; import javax.servlet.http.*; regds maha anna
[This message has been edited by maha anna (edited September 11, 2000).]
maha anna
Ranch Hand
Joined: Jan 31, 2000
Posts: 1467
posted
0
zhangzh, I just missed your previous post. For the 2nd error you got, please import sub-package 'javax.servlet.http'. So include the following also in your servlet code. import javax.servlet.http.*; regds maha anna
zhangzh
Greenhorn
Joined: Sep 22, 2000
Posts: 10
posted
0
GOT IT! thank you!!! zhangzh BUT! the following source code is from original JSDK2.1 download bundle from SUN!!!(windows platform)
file name after unzip: jsdk2.1\examples\servlets\HelloWorld.html Source Code for HelloWorld Example import java.io.*; import java.servlet.*; (i cannot believe it!) import javax.servlet.*; 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("<body>"); out.println("<head>"); out.println("<title>Hello World!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello World!</h1>"); out.println("</body>"); out.println("</html>"); } }"