有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JSP编译错误令牌“throws”语法错误,应为throw

我们在Tomcat7服务器上托管了一个JSP应用程序。作为构建过程的一部分,我们运行了一些自动测试,通过HtmlUnit调用这些JSP页面。 我们注意到,当一些测试试图访问JSP文件时,会出现间歇性的JSP编译错误。这似乎与任何特定的测试无关

例如,我们遇到的最后一个编译错误是:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [1] in the generated java file: [/tmp/myproject/work/Tomcat/localhost/_/org/apache/jsp/WEB_002dINF/jsp/admin/home_jsp.java]
Syntax error on tokens, delete these tokens

An error occurred at line: [97] in the generated java file: [/tmp/myproject/work/Tomcat/localhost/_/org/apache/jsp/WEB_002dINF/jsp/admin/home_jsp.java]
Syntax error on token(s), misplaced construct(s)

An error occurred at line: 1 in the jsp file: /WEB-INF/jspf/taglibs.jspf
Syntax error on tokens, delete these tokens
1: <%@ taglib uri="http://www.springframework.org/security/tags" prefix="authz" %>
2: <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
3: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
4: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


An error occurred at line: 1 in the jsp file: /WEB-INF/jspf/taglibs.jspf
Syntax error on token "}", delete this token
1: <%@ taglib uri="http://www.springframework.org/security/tags" prefix="authz" %>
2: <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
3: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
4: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


An error occurred at line: 1 in the jsp file: /WEB-INF/jspf/taglibs.jspf
Syntax error on token "(", ; expected
1: <%@ taglib uri="http://www.springframework.org/security/tags" prefix="authz" %>
2: <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
3: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
4: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


An error occurred at line: 1 in the jsp file: /WEB-INF/jspf/taglibs.jspf
Syntax error on token(s), misplaced construct(s)
1: <%@ taglib uri="http://www.springframework.org/security/tags" prefix="authz" %>
2: <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
3: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
4: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


An error occurred at line: 1 in the jsp file: /WEB-INF/jspf/taglibs.jspf
Syntax error on token(s), misplaced construct(s)
1: <%@ taglib uri="http://www.springframework.org/security/tags" prefix="authz" %>
2: <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
3: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
4: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


An error occurred at line: 1 in the jsp file: /WEB-INF/jspf/taglibs.jspf
Syntax error on token "throws", throw expected
1: <%@ taglib uri="http://www.springframework.org/security/tags" prefix="authz" %>
2: <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
3: <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
4: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


An error occurred at line: 1 in the jsp file: /WEB-INF/jsp/admin/home.jsp
Syntax error on token "}", delete this token
1: <%@ include file="/WEB-INF/jspf/taglibs.jspf" %>
2: <html>
3: <head>
4:     <title>Administrator Home</title>

无论是在本地环境中,还是在负责运行这些系统测试的环境之外的任何其他环境中,我们都看不到这些错误,是的,我们使用相同的代码库

这些错误似乎只发生在第一次访问JSP文件时,因为我可以在Tomcat JSP工作目录中看到有一个home_JSP。java和一个home_jsp。类,这意味着jsp文件已正确地转换为servlet类,然后在以后正确编译。此外,我还看了一下家里的房子。java文件,无法看到与JSP编译器报告的编译错误相对应的任何明显错误

任何有助于解决这个问题的想法/建议都将不胜感激

干杯, 奥利维尔


共 (1) 个答案

  1. # 1 楼答案

    我们不知道有两个Tomcat实例实际上使用同一个JSP工作目录

    我们已经改变了这一点,这样每个实例都使用自己的工作文件夹,此后我们就再也没有看到过这个问题

    这并没有给出真正的根本原因,但至少解决了我们的问题