我的一个包里面有4个类,全是public的,有LongLivedCookie,CookieUtility,RegistrationForm,RegistrationServlet,其中RegistrationForm要用到CookieUtility,开始的时候我没在CLASSPATH里面包含包的上一级目录,所以总是出现Unresolved symbol错误,但是现在包含了怎么还是说不能access这个CookieUtility类呢?
C:\Tomcat5.0\webapps\myapps\WEB-INF\classes\coreservlets\RegistrationForm.java:27: cannot access coreservlets.CookieUtilities
bad class file: C:\Tomcat5.0\webapps\ROOT\WEB-INF\classes\coreservlets\CookieUtilities.java
file does not contain class coreservlets.CookieUtilities
Please remove or make sure it appears in the correct subdirectory of the classpath.
CookieUtilities.getCookieValue(request, "firstName", "");
^
1 errorTool completed with exit code 1
顺便问一句,我的textpad在装了一个中文版出错之后,我装回英文版,颜色就都变成黑色的了,没有一点提示的颜色,郁闷死了,重装还是不行,Eclipse里面我也不知道怎么编译运行Servlet,请高手指点一下,多谢了
C:\Tomcat5.0\webapps\myapps\WEB-INF\classes\coreservlets\RegistrationForm.java:27: cannot access coreservlets.CookieUtilities
bad class file: C:\Tomcat5.0\webapps\ROOT\WEB-INF\classes\coreservlets\CookieUtilities.java
file does not contain class coreservlets.CookieUtilities
Please remove or make sure it appears in the correct subdirectory of the classpath.
CookieUtilities.getCookieValue(request, "firstName", "");
^
1 errorTool completed with exit code 1
顺便问一句,我的textpad在装了一个中文版出错之后,我装回英文版,颜色就都变成黑色的了,没有一点提示的颜色,郁闷死了,重装还是不行,Eclipse里面我也不知道怎么编译运行Servlet,请高手指点一下,多谢了
当要用到这个class文件的时候,import mypackage;
重新编译一下吧。
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import coreservlets.*;/** Servlet that displays an HTML form to collect user's
* first name, last name, and email address. Uses cookies
* to determine the initial values of each of those
* form fields.
* <P>
* Taken from Core Servlets and JavaServer Pages 2nd Edition
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2003 Marty Hall; may be freely used or adapted.
*/public class RegistrationForm extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String actionURL =
"/servlet/RegistrationServlet";
String firstName =
CookieUtilities.getCookieValue(request, "firstName", "");
String lastName =
CookieUtilities.getCookieValue(request, "lastName", "");
String emailAddress =
CookieUtilities.getCookieValue(request, "emailAddress",
"");
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
String title = "Please Register";
out.println
(docType +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<CENTER>\n" +
"<H1>" + title + "</H1>\n" +
"<FORM ACTION=\"" + actionURL + "\">\n" +
"First Name:\n" +
" <INPUT TYPE=\"TEXT\" NAME=\"firstName\" " +
"VALUE=\"" + firstName + "\"><BR>\n" +
"Last Name:\n" +
" <INPUT TYPE=\"TEXT\" NAME=\"lastName\" " +
"VALUE=\"" + lastName + "\"><BR>\n" +
"Email Address: \n" +
" <INPUT TYPE=\"TEXT\" NAME=\"emailAddress\" " +
"VALUE=\"" + emailAddress + "\"><P>\n" +
"<INPUT TYPE=\"SUBMIT\" VALUE=\"Register\">\n" +
"</FORM></CENTER></BODY></HTML>");
}
}
先前我没有写上面那一句import coreservlets,现在加上了,还是有错
CookieUtility类前面我写了package coreservelts呀,怎么回事呀,晕死了
----------------------------------------
加 import coreservlets.*;
看看。
CookieUtilities.getCookieValue不是一个static函数,需要先实例化
CookieUtilities cu = new CookieUtilities();
cu.getCookieValue........