Eclipse表示JSP中没有字母的行存在语法错误

时间:2018-07-26 13:52:00

标签: jsp

我正在尝试创建一个从数据库中删除条目的JSP,但这给了我一个语法错误,其中唯一的问题是<%。没有红色下划线,只有在行号旁边带有x的红色圆圈。我使用了此tutorial中的代码,而且我相当确定我没有错别字。这是我的代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="PlaygroundDeleteSuccess.jsp">
<table>
<tr>
<td>Enter the Equipment ID you wish to delete:</td>
<td><input type="text" name="id">
</td>
<tr>
<td></td>
<td><input type="submit" value="Delete"></td>
</tr>
</table>
</form>
<%! String driverName = "org.postgresql.Driver"; %>
<%! String url = "jdbc:postgresql://192.168.1.235:5432/postgres"; %>
<%! String user = "postgres"; %>
<%! String pass = "password"; %>
<%
String id = request.getParameter("id");

if (id != null) {
    Connection con = null;
    PreparedStatement ps = null;
    int equipID = Integer.parseInt(id);
    try {
        Class.forName(driverName);
        con = DriverManager.getConnection(url, user, pass);
        String sql = "DELETE FROM playground WHERE equip_id = " + equipID;
        ps = con.prepareStatement(sql);
        int i = ps.executeUpdate();

        if (i >0) {
        %>
        <jsp:forward page="/PlaygroundDeleteSuccess.jsp"/>
        <%
        } else {
        %>
        <jsp:forward page="/PlaygroundDeleteFail.jsp"/>
        <% //This is the line that the red circle with the x show up on
        }
        } catch (SQLException e) {
            request.setAttribute("error", e);
            out.println(e);
        }
        %>
</body>
</html>

以及当我尝试访问该页面时的stacktrace:

Type Exception Report

Message Unable to compile class for JSP:

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

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

An error occurred at line: [196] in the generated java file: [C:\JavaEE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\G2\org\apache\jsp\Pages\PlaygroundDelete_jsp.java]
Syntax error, insert "else Statement" to complete IfStatement

An error occurred at line: [196] in the generated java file: [C:\JavaEE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\G2\org\apache\jsp\Pages\PlaygroundDelete_jsp.java]
Syntax error, insert "}" to complete Block

An error occurred at line: [213] in the generated java file: [C:\JavaEE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\G2\org\apache\jsp\Pages\PlaygroundDelete_jsp.java]
Syntax error on token "}", delete this token

An error occurred at line: [214] in the generated java file: [C:\JavaEE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\G2\org\apache\jsp\Pages\PlaygroundDelete_jsp.java]
Syntax error, insert "}" to complete ClassBody

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:473)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.

当我将鼠标悬停在红色圆圈上时,它说:

 Multiple annotations found at this line:    
    - Syntax error, insert "}" to complete ClassBody    
    - Syntax error, insert "else Statement" to complete IfStatement   
    - Syntax error, insert "}" to complete Block
    - Syntax error on token "}", delete this token

编辑:现在由于某种原因,每当我刷新页面时,它有时就会加载,有时会抛出相同的500错误。

1 个答案:

答案 0 :(得分:0)

正确看... 如果{},您的try {} catch {}块位于 因此,如果在关闭catch支撑后关闭支撑,您就不会关闭。