当前位置: 技术问答>java相关
书上的简单例子却javac不过,请高手指点
来源: 互联网 发布时间:2014-12-29
本文导语: 下面是书上的例子 //===================== Morning.java ==================== import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Morning extends HttpServlet { public void service(HttpServletRequest req, ...
下面是书上的例子
//===================== Morning.java ====================
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Morning extends HttpServlet
{
public void service(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html; charset=Big5");
PrintWriter pw=res.getWriter();
pw.println("");
pw.println("");
pw.println("Morning");
pw.println("");
pw.println("");
pw.println("Good Morning!!
");
pw.println("Ν!!");
pw.println("");
pw.println("");
}
}
但是我在命令行中输入javac Morning.java,得到的结果为
import javax.servlet.http.*;
^
Morning.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class Morning
public class Morning extends HttpServlet
^
Morning.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class Morning
public void service(HttpServletRequest req,
^
Morning.java:8: cannot resolve symbol
symbol : class HttpServletResponse
location: class Morning
HttpServletResponse res)
^
Morning.java:9: cannot resolve symbol
symbol : class ServletException
location: class Morning
throws ServletException, IOException
^
6 errors
这是为何?
另外,我在autoexec.bat中输入:
@echo off
prompt $p$g
path.;c:jbuilder4jdk1.3bin;
set classpath=.;c:jbuilder4jdk1.3libtools.jar
@echo on
应该没问题吧?(我安装了JBuilder4.0,JDK就用它自带的)
//===================== Morning.java ====================
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Morning extends HttpServlet
{
public void service(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html; charset=Big5");
PrintWriter pw=res.getWriter();
pw.println("");
pw.println("");
pw.println("Morning");
pw.println("");
pw.println("");
pw.println("Good Morning!!
");
pw.println("Ν!!");
pw.println("");
pw.println("");
}
}
但是我在命令行中输入javac Morning.java,得到的结果为
import javax.servlet.http.*;
^
Morning.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class Morning
public class Morning extends HttpServlet
^
Morning.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class Morning
public void service(HttpServletRequest req,
^
Morning.java:8: cannot resolve symbol
symbol : class HttpServletResponse
location: class Morning
HttpServletResponse res)
^
Morning.java:9: cannot resolve symbol
symbol : class ServletException
location: class Morning
throws ServletException, IOException
^
6 errors
这是为何?
另外,我在autoexec.bat中输入:
@echo off
prompt $p$g
path.;c:jbuilder4jdk1.3bin;
set classpath=.;c:jbuilder4jdk1.3libtools.jar
@echo on
应该没问题吧?(我安装了JBuilder4.0,JDK就用它自带的)
|
你去sun的网站上down一个jsdk2_1-win.zip,
然后,把它里面的*.jar放到c:jbuilder4jdk1.3jrelibext(如果没有目录,那么自己建)
然后,去掉autoexec.bat里的classpath.
然后,在计算机里查找java.exe,只留下c:jbuilder4jdk1.3bin里的那个,删除其它的。
就不会再出现其它错误了。
然后,把它里面的*.jar放到c:jbuilder4jdk1.3jrelibext(如果没有目录,那么自己建)
然后,去掉autoexec.bat里的classpath.
然后,在计算机里查找java.exe,只留下c:jbuilder4jdk1.3bin里的那个,删除其它的。
就不会再出现其它错误了。
|
http://www.csdn.net/expert/topic/85/85391.shtm