干脆贴出来大家还清楚一点 /**以下为Count.java package moreservlets;import java.util.Date; /** simple bean used by countertag. ror boats emamples*/public class Count{ private int count=1; private Date startDate = new Date();public int getCount(){ return(count); }public void incrementCount(){ count++; }public Date getStartDate(){ return (startDate); }} package moreservlets;import javax.servlet.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import java.text.*;/**以下为CounterTag.java /** Tag that outputs a web-ap-specific hit count. *for boats example * <p> * the actual name of the tag is not defined here; * that is given by the tag library descriptor (tld) * in the jsp file. */public class CounterTag extends TagSupport{ public int dostartTag(){ try{ ServletContext application= pageContext.getServletContext(); Count count=(Count)application.getAttribut("count"); if(count== null){ count=new Count(); application.setAttribute("count",count); } DateFormat formatter= DateFormat.getDateInstance(DateFormat.MEDIUM); JspWriter out= pageContext.getOut(); out.println("<BR CLEAR=\"ALL\"><BR><HR>"); out.println("This site has received" + count.getCount() + "hits since" + formatter.format(count.getStartDate())+ "."); count.incrementCount(); }catch(IOException ioe){ System.out.println("Error in CounterTag: " + ioe); } return (SKIP_BODY); } }以上两个文件在同一个文件夹moreservlets中
同一个文件夹不用import,真要用 就import Count;
不用IMPORT为什么提示cannot resolve symbol symbol :class Count locationg: class moreservlets.countertag Count count=<Count>application.getAttribut<"count">; ^ ......
/**以下为Count.java
package moreservlets;import java.util.Date;
/** simple bean used by countertag. ror boats emamples*/public class Count{
private int count=1;
private Date startDate = new Date();public int getCount(){
return(count);
}public void incrementCount(){
count++;
}public Date getStartDate(){
return (startDate);
}}
package moreservlets;import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.text.*;/**以下为CounterTag.java
/**
Tag that outputs a web-ap-specific hit count.
*for boats example
* <p>
* the actual name of the tag is not defined here;
* that is given by the tag library descriptor (tld)
* in the jsp file.
*/public class CounterTag extends TagSupport{
public int dostartTag(){
try{
ServletContext application=
pageContext.getServletContext();
Count count=(Count)application.getAttribut("count");
if(count== null){
count=new Count();
application.setAttribute("count",count);
}
DateFormat formatter=
DateFormat.getDateInstance(DateFormat.MEDIUM);
JspWriter out= pageContext.getOut();
out.println("<BR CLEAR=\"ALL\"><BR><HR>");
out.println("This site has received" + count.getCount()
+ "hits since" + formatter.format(count.getStartDate())+
".");
count.incrementCount();
}catch(IOException ioe){
System.out.println("Error in CounterTag: " + ioe);
}
return (SKIP_BODY);
}
}以上两个文件在同一个文件夹moreservlets中
就import Count;
symbol :class Count
locationg: class moreservlets.countertag
Count count=<Count>application.getAttribut<"count">;
^
......
前面的.;是用来识别同一个文件夹里面的类