日期:2014-05-17  浏览次数:20704 次

jsp导入class文件出错
从jsp文件导入MyCounter.class文件,可是总出错,感觉可能是导入路径有问题,
但又不知道哪出错,需要怎么设置,

URL http://localhost:8080/examples/servlets/servlet 对应的路径是
  E:\apache-tomcat-7.0.22\webapps\examples\WEB-INF\classes,
这个设置是tomcat系统默认的,没有改过。

哪个朋友能帮忙看出问题?


■环境
tomcat ver7.0.22 , jdk6

■jsp文件 位置 E:\apache-tomcat-7.0.22\webapps\examples\jsp\L1033.jps
-----------------------------------
<%@ page import="MyCounter" contentType ="text/html; charset=Shift_JIS"%>

<%
MyCounter counter=null;
counter=new MyCounter(pageContext.getServletContext().getRealPath("/") + 
"count.dat");
int intCounter=0;
 
try{
intCounter=Integer.parseInt(counter.getCount());
}catch(Exception ex){
out.println("Error:" + ex);
}
...省略
%>
------------------------------------

■class文件 位置 E:\apache-tomcat-7.0.22\webapps\examples\WEB-INF\classes\MyCounter.class
该文件javac编译OK,应该没问题。

■出错
MyCounter cannot be resolved to a type
3: <%@ page import="MyCounter" contentType ="text/html; charset=Shift_JIS"%>
4: 
5: <%
6: MyCounter counter=null;
7: counter=new MyCounter(pageContext.getServletContext().getRealPath("/") + 
8: "count.dat");
9: int intCounter=0;






------解决方案--------------------
MyCounter有没有包路径,有包路径的话 应该写 <%@ page import="xxx.MyCounter" contentType ="text/html; charset=Shift_JIS"%>
------解决方案--------------------
应该是类的路径不对,反编译下MyCounter.class这个类,看一下它的package,然后引入这个类后写<%@ page import="xxx.MyCounter" contentType ="text/html; charset=Shift_JIS"%>,xxx为package路径。