• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.servlet.* cannot import, but javax.servlet.* ok???

 
zhangzh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be wrong but I don't think java.servlet package exists.
Vijay
 
zhangzh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>");
}
}"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic