×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

hi,Japper, need your help!

本文发表在 rolia.net 枫下论坛I test a Servlet program to know more about the class GenericServlet .But I met some errors. Why?
The program is HelloWorldSerlet.java:

import java.io.*;
import java.util.Date;

import javax.Servlet.*;
public class HelloWorldServlet extends GenericServlet
{
String initString;
public void init(ServletConfig config)
throw ServletException
{
super.init(config);
initString=new String("I have been initialized");
}
public void Service(ServletRequest req,ServletRespone res)
{
Date today=new Date();
ServletOutputStream out=res.getOutputStream();
out.println("Hello World");
out.println(today.toString());
out.println(getServletInfo());
}
public void Destroy()
{
}
pubic String getServletInfo()
{
return "Create a page that says Hello World and send date back produced by djf";
}
}


And I already to set the path=c:\jdk1.1.8\bin;
CLASSPATH=c:\jdk1.1.8\class\classes.zip
And I used "javac HelloWorldServlet.java" to compile it,but I got errors:
"Package javax.Servlet not found in import."
"Superclass GenericServlet of class HelloWorldServlet not found..."
I check my path and classpath for many times, I have no idea ! :-(
Help me!更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / hi,Japper, need your help!
    本文发表在 rolia.net 枫下论坛I test a Servlet program to know more about the class GenericServlet .But I met some errors. Why?
    The program is HelloWorldSerlet.java:

    import java.io.*;
    import java.util.Date;

    import javax.Servlet.*;
    public class HelloWorldServlet extends GenericServlet
    {
    String initString;
    public void init(ServletConfig config)
    throw ServletException
    {
    super.init(config);
    initString=new String("I have been initialized");
    }
    public void Service(ServletRequest req,ServletRespone res)
    {
    Date today=new Date();
    ServletOutputStream out=res.getOutputStream();
    out.println("Hello World");
    out.println(today.toString());
    out.println(getServletInfo());
    }
    public void Destroy()
    {
    }
    pubic String getServletInfo()
    {
    return "Create a page that says Hello World and send date back produced by djf";
    }
    }


    And I already to set the path=c:\jdk1.1.8\bin;
    CLASSPATH=c:\jdk1.1.8\class\classes.zip
    And I used "javac HelloWorldServlet.java" to compile it,but I got errors:
    "Package javax.Servlet not found in import."
    "Superclass GenericServlet of class HelloWorldServlet not found..."
    I check my path and classpath for many times, I have no idea ! :-(
    Help me!更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • You don't have javax.servlet.* package
      JDK, whatever its version is, contains only
      "core" java library classes. Servlet, JSP, EJB, JMS, JTS, .... consists in the so-called J2EE.

      Servlet and JSP package come by two different ways: 1) Java Servlet Development Kid(JSDK, servlet.jar); or 2) Java 2 Enterprise Edition(J2EE, j2ee.jar). Since you are working on Servlet, you need to download either of them. Go to java.sun.com and browse its API.