javaWeb工程提示:org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 25 in the jsp file: /index.jsp
Test cannot be resolved to a type
22:
23: <body>
24: This is my JSP page. <br>
25: <% Test t=new Test();
26: t.Show(); %>
27: </body>
28: </html>
为了测试我给Test的代码很简单:
public class Test {
int as=20;
public void Show()
{
System.out.println(as);
}
}
保存后没提示错误。但运行就提示上面的错误。Tomcat没有编成功。apache-tomcat-6.0.32\webapps\Cart\WEB-INF\classes下根本没有class文件。
补充:import 已经加了。不然jsp中都不认Test的。
好吧。我换了另一个版本的MyEclipse。这个代码没错但就是不对的问题解决了。类似的这些天遇到了好多,发现重启了服务器就对了。真是的!!!
答案:我测试了下,可以的啊:运行时在后台输出20。
//*****JSP页面代码**********
<%@ page import="com.Test" %>
<html>
<head>
<title>TestPage</title>
</head>
<body>
<%
new Test().Show();
%>
</body>
</html>
//*****com.Test类为*************:
package com;
public class Test {
private int as = 20;
public void Show() {
System.out.println(as);
}
}
其他:正如楼下的,要引进类 应该是配置错误
你把类copy 过去看一看 我看了下,你那个还要加上包名 ,如java.lancs 他是放在类似这些的包里的,你在建立的文件夹下面还要建立包路径文件夹!!!
如果你是用eclipse的话,可以右击你的项目,现在属性(Properties) 然后再选Java Build Path ,选址Libraries选项卡,你会在右边看到Add Class Folder,选择你class的路径就行了,(可以在你项目的下建立一个文件夹,名称无所谓,然后将类放进去)
在顶部加上
<%@ page import="Test的路径.Test"%>
你用的什么编译器? org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 180 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on token "<", invalid AssignmentOperator
An error occurred at line: 180 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on token "=", != expected
An error occurred at line: 188 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression
An error occurred at line: 188 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on token "<", delete this token
An error occurred at line: 188 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens
An error occurred at line: 188 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression
An error occurred at line: 188 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on token "<", invalid Expression
An error occurred at line: 188 in the jsp file: /jsp/Login-main.jsp
Generated servlet error:
Syntax error on tokens, Expression expected instead
Generated servlet error:
Syntax error, insert "}" to complete Block
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
上一个:java 中 Math.round() Math.ceil() Math.floor()区别
下一个:有没有一个java的IDE 可以自由拉swing控件 而不用 像eclipse那样要自己去声明了才可以用的....