<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="mytest.Test"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Test t = new Test("qing");
out.println(t.getStr());
%>
</body>
</html>目录结构为:
qing
-- src
-- mytest
-- Test.java
-- META-INF
-- WEB-INF
-- classes
-- web.xml
-- test.jsp错误提示为:
type Exception reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
Only a type can be imported. mytest.Test resolves to a packageAn error occurred at line: 11 in the jsp file: /qq/test.jsp
Test cannot be resolved to a type
8: </head>
9: <body>
10: <%
11: Test t = new Test("qing");
12: out.println(t.getStr());
13: %>
14: </body>
An error occurred at line: 11 in the jsp file: /qq/test.jsp
Test cannot be resolved to a type
8: </head>
9: <body>
10: <%
11: Test t = new Test("qing");
12: out.println(t.getStr());
13: %>
14: </body>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
private String str;
public Test(String str){
this.str = str;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="mytest.Test"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here </title>
</head>
<body>
<%
Test t = new Test("qing");
out.println(t.getStr());
%>
</body>
</html>
这样试试看
你的应用程序名是qq,还是qing 是不是项目名搞错了.
把这句分开到 <%@ page import="mytest.Test"%>试试看
mytest.Test t = new mytest.Test("qing");
out.println(t.getStr());
%>
你的 jsp 文件 是放在qq下还是在qing下面 ?好像是你是路径不对....检查改哈子....没问题的..
原因是jsp文件有错
和类没有关系
没有的话复制过去
我重新建一个空的工程, 里面就一个JSP文件, 我再把这个JAR文件加到工程中, 编译器没提示错误, 但是打开地址还是说找不到包.
另外我导入像<%@ page import="java.util.Date" %> 却没有问题, 而且也可以用.
tomcat也试了4.1 / 5.5 / 6.0版本,结果都是一样. 工具用eclipse3.3 eclipse3.2 都是那样.
我重装系统, 直接配置JDK1.5, 解压eclipse工具, 然后再安装tomcat, 建个新的工程, 运行, 结果还是找不到包, 不管包名有没有, 也不管包名有多少层, 我自己手动的用DOS编译JAVA文件, 还是不行, 再手动打包, 也是一样.
我都有加到工程里面的, 而且也肯定成功添加了的, 因为在文件里面没有红色的波浪线, 如果没有导入的话是有的.
我确定真的加到工程里面的了, 但是又真的是提示找不到.不知道是怎么的回事, 我真的想不到还有其他的什么办法了. 如果你有我还没用过的方法, 都可以提出来.
多找几篇配置的文章,看看自己哪些地方没有配。
如果别人那里都能出来,那肯定是你的一些问题。