Topic: 你好:请问为什么JAVA程序不能编译? |
Print this page |
1.你好:请问为什么JAVA程序不能编译? | Copy to clipboard |
Posted by: guopu1 Posted on: 2005-03-28 15:09 你好: 请问为什么JAVA程序不能编译? 我在win2000 C:上安装的是jswdk-1.0和j2sdk1.4.2_07环境变量设为: CLASSPATH=c:\j2sdk1.4.2_07\lib\tools.jar;c:\j2sdk1.4.2_07\jre\lib\rt.jar; PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\j2sdk1.4.2_07\bin 源程序是jswdk-1.0里的现成JAVA文件: /* $Id: SnoopServlet.java,v 1.1 1999/03/17 01:17:20 duncan Exp $ * */ import java.io.IOException; import java.util.Enumeration; import javax.servlet.*; import javax.servlet.http.*; /** * * * @author James Duncan Davidson <duncan@eng.sun.com> */ public class SnoopServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletConfig config = getServletConfig(); ServletOutputStream out = response.getOutputStream(); out.println("Snoop Servlet"); out.println(); out.println("Init Parameters"); Enumeration e = config.getInitParameterNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); String value = config.getInitParameter(key); out.println(" " + key + " = " + value); } out.println(); out.println("Context attributes:"); ServletContext context = config.getServletContext(); Enumeration enum = context.getAttributeNames(); while (enum.hasMoreElements()) { String key = (String)enum.nextElement(); Object value = context.getAttribute(key); out.println(" " + key + " = " + value); } out.println(); out.println("javax.servlet.Servlet methods"); out.println(); out.println("Attribute names in this request:"); e = request.getAttributeNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); Object value = request.getAttribute(key); out.println(" " + key + " = " + value); } out.println(); out.println("Protocol: " + request.getProtocol()); out.println("Scheme: " + request.getScheme()); out.println("Server Name: " + request.getServerName()); out.println("Server Port: " + request.getServerPort()); out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo()); out.println("Remote Addr: " + request.getRemoteAddr()); out.println("Remote Host: " + request.getRemoteHost()); out.println("Character Encoding: " + request.getCharacterEncoding()); out.println("Content Length: " + request.getContentLength()); out.println("Content Type: "+ request.getContentType()); out.println(); out.println("Parameter names in this request"); e = request.getParameterNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); String[] values = request.getParameterValues(key); out.print(" " + key + " = "); for(int i = 0; i < values.length; i++) { out.print(values[i] + " "); } out.println(); } out.println(); out.println("javax.servlet.http.HttpServletRequest methods"); out.println(); out.println("Headers in this request"); e = request.getHeaderNames(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); String value = request.getHeader(key); out.println(" " + key + " : " + value); } out.println(); out.println("Cookies in this request"); Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; out.println(" " + cookie.getName() + " = " + cookie.getValue()); } out.println(); out.println("Auth Type: " + request.getAuthType()); out.println("HTTP Method: " + request.getMethod()); out.println("Path Info: " + request.getPathInfo()); out.println("Path Trans: " + request.getPathTranslated()); out.println("Query String: " + request.getQueryString()); out.println("Remote User: " + request.getRemoteUser()); out.println("Session Id: " + request.getRequestedSessionId()); out.println("Request URI: " + request.getRequestURI()); out.println("Servlet Path: " + request.getServletPath()); out.println(); out.println("Session Information"); HttpSession session = request.getSession(true); out.println("Created: " + session.getCreationTime()); out.println("ID: " + session.getId()); out.println("Last Accessed: " + session.getLastAccessedTime()); out.println("Max Inactive Interval: " + session.getMaxInactiveInterval()); out.println(); out.println("Values: "); String[] valueNames = session.getValueNames(); for (int i = 0; i < valueNames.length; i++) { out.println(" " + valueNames[i] + " = " + session.getValue(valueNames[i])); } out.println(); } } 编译时出错提示为: C:\>javac et.java et.java:16: class SnoopServlet is public, should be declared in a file named Sno opServlet.java public class SnoopServlet extends HttpServlet { ^ et.java:7: package javax.servlet does not exist import javax.servlet.*; ^ et.java:8: package javax.servlet.http does not exist import javax.servlet.http.*; ^ et.java:16: cannot resolve symbol symbol : class HttpServlet location: class SnoopServlet public class SnoopServlet extends HttpServlet { ^ et.java:18: cannot resolve symbol symbol : class HttpServletRequest location: class SnoopServlet public void doGet(HttpServletRequest request, HttpServletResponse response) ^ et.java:18: cannot resolve symbol symbol : class HttpServletResponse location: class SnoopServlet public void doGet(HttpServletRequest request, HttpServletResponse response) ^ et.java:19: cannot resolve symbol symbol : class ServletException location: class SnoopServlet throws ServletException, IOException ^ et.java:21: cannot resolve symbol symbol : class ServletConfig location: class SnoopServlet ServletConfig config = getServletConfig(); ^ et.java:21: cannot resolve symbol symbol : method getServletConfig () location: class SnoopServlet ServletConfig config = getServletConfig(); ^ et.java:22: cannot resolve symbol symbol : class ServletOutputStream location: class SnoopServlet ServletOutputStream out = response.getOutputStream(); ^ et.java:34: cannot resolve symbol symbol : class ServletContext location: class SnoopServlet ServletContext context = config.getServletContext(); ^ et.java:57: cannot resolve symbol symbol : method getServletConfig () location: class SnoopServlet out.println("Server Info: " + getServletConfig().getServletContext().get ServerInfo()); ^ et.java:87: cannot resolve symbol symbol : class Cookie location: class SnoopServlet Cookie[] cookies = request.getCookies(); ^ et.java:89: cannot resolve symbol symbol : class Cookie location: class SnoopServlet Cookie cookie = cookies[i]; ^ et.java:106: cannot resolve symbol symbol : class HttpSession location: class SnoopServlet HttpSession session = request.getSession(true); ^ 15 errors |
2.Re:你好:请问为什么JAVA程序不能编译? [Re: guopu1] | Copy to clipboard |
Posted by: zhaojs Posted on: 2005-03-28 16:06 你的代码是要实现servlet吧? |
3.Re:你好:请问为什么JAVA程序不能编译? [Re: guopu1] | Copy to clipboard |
Posted by: qingbo777 Posted on: 2005-03-28 16:31 简直有太多问题. 首先: 编译时出错提示为: C:\>javac et.java 很明显,你的文件名起成了et.java.可是你的public class 名是SnoopServlet.两者要一致. 再者: 你的CLASSPATH变量没有加入"."路径,就是当前目录. 并且你没有把servlet-api.jar(tomcat下)的包加进去啊. |
4.Re:你好:请问为什么JAVA程序不能编译? [Re: guopu1] | Copy to clipboard |
Posted by: why Posted on: 2005-03-28 20:12 this duplicated topic was deleted: http://www.cjsdn.net/post/view?bid=1&id=139067 I wrote on 2005-03-27: you need to add to the classpath the servlet.jar of your web container, jwsdk. better use something newer and better like Tomcat or Resin. and guopu1 replied: Thank you for answering my question! I add the servlet.jar of your web container, jwsdk to the classpath ,but I still can not javac the java file. Try something simpler (well, smaller, shorter) first! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |