无法达到例外的根本原因

时间:2013-01-17 07:54:37

标签: java jsp tomcat java-ee

在尝试运行jsp页面时,我遇到以下例外情况:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it 
from fulfilling this request.

exception

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

An error occurred at line: 17 in the generated java file
Syntax error on token ";", delete this token

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:644)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.22 logs.

看到这些例外,我无法找到它的根本原因。任何人都可以帮助我。我的IDE没有显示任何可能表明我正在尝试编译有错误的jsp的红色标记。相反,它没有显示它的迹象。

注意:我也没有看到生成的Java文件,例外情况

JSP代码:

<%-- 
Document   : index
Created on : Dec 8, 2012, 10:55:43 AM
Author     : user
--%>

<%@page import="internet.CommunicationWithServer.PingTheServer"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page import="internet.CommunicationWithServer.SendNodeInfo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="internet.HelperClasses.*;" %>
<%@page import="General.HelperClasses.*;" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Client Nappster</title>
    <style type="text/css">
        @import url("css/index_css.css");
    </style>
</head>
<body bgcolor="#000000">
<center> <h2 id="Head">Client Nappster</h2> </center>

<center> <h4 id="Head"><%= new GregorianCalendar().getTime().toString() %></h4> </center>

<%-- Call a method that checks for the internet connection --%>
<%! 
   boolean isConnectionAvailable;
   String networkIP;
%>
<% if(request.getAttribute("File-Sharing-Status") != null && ((Boolean)request.getAttribute("File-Sharing-Status")) == true) {%>
<script type="text/javascript"> alert("Success ! File shared with the nappster server"); </script>
<%}%>
<%
    isConnectionAvailable = new CheckConnection().checkConnection();
    if(isConnectionAvailable) {
        // send a message,the app is conneted to the nappster central server
        System.out.println("returned true");
        // call a method that sends the client's IP address to the nappster central server
        networkIP = new ClientAddress().getNetworkIP();
        // send to the server the address and the name of the node online
        boolean informationSent = new SendNodeInfo().sendInfo(networkIP);
        // call a method that starts a thread that after certain intervals checks if the node is still connected 
        // to the internet
        new PingTheServer().startPingThread();
        // make a 'Shared' Directory
        boolean directoryMade = new DirectoryMaker().makeDirectory(request.getServletContext().getRealPath("/"), "Shared");
        if(directoryMade == false) {
            //Warning : Unable to make a directory | Directory already exists
            System.out.println("Unable to create the 'Shared' directory | or directory already exists");
        }
    } else {
        // send an error message,unable to connect the app to the napster cental server
        System.out.println("returned false");
    }
%>

<jsp:include page="EmbeddedJSP/form_table.jsp" />

</body>

EmbeddedJSP / form_table.jsp:

    <%@page import="internet.CommunicationWithServer.QueryConnectedNodes"%>
    <%@page import="java.io.File"%>
    <%@page import="java.io.FileReader"%>
    <%@page import="java.io.BufferedReader"%>
    <%@page import="java.util.Iterator"%>
    <%@page import="java.util.ArrayList"%>
    <%@page import="General.HelperClasses.Stashed"%>
    <%@page import="internet.CommunicationWithServer.QueryFileNames"%>

    <%! String fileSharingStatusString; 
        Boolean fileSharingStatus;
        String nodesConnected;
        boolean ncStashed;
    %>

    <% BufferedReader sharingStatusReader = new BufferedReader(new FileReader(request.getServletContext().getRealPath("/") + Constants.FilePaths.fstPath));
   while((fileSharingStatusString = sharingStatusReader.readLine()) != null) {
       fileSharingStatus = new Boolean(fileSharingStatusString.trim());
   }
    %>

   <% if(new File(request.getServletContext().getRealPath("/") + Constants.FilePaths.nlPath).exists())
        ncStashed = true;
   %>

   <table width="100%" border="+3" id="Table_border_color">
    <tr>
        <th id="Nodes_Connected_Heading"> Nodes Connected </th>
        <th id="Files_to_be_shared_heading"> Select a File to share  </th>
        <th id="Files_shared_heading"> Files Shared  </th>
    </tr>

    <tr>
        <td width="20%" id="List_of_nodes_connected"> List <br />
            <%-- Get the list of all the nodes connected to the nappster server --%>
            <% if(new QueryConnectedNodes().getConnectedNodes() && ncStashed) {
                BufferedReader nodesConnectedReader = new BufferedReader(new FileReader(Constants.FilePaths.nlPath));
                String line;
                while((line = nodesConnectedReader.readLine()) != null) {
            %>
                    <%= line %>
            <%  } // end of while loop
              } // end of if block 
                  else {
            %>
            <em>No node connected to the nappster server !</em>
            <%}%>
        </td>
        <td width="60%" valign="top" align="center">  
            <form method="post" action="SendTheFileName" enctype="multipart/form-data">
                <div id="Files_to_be_shared"> 
                      <input type="file" id="File" name="FileTag" />
                      <input type="submit" value="Share" /> 
                    </div>
            </form>
        </td>

        <td id="List_of_files_shared">
            List of files shared. <br />
            <%-- check if the user has shared any file --%>
            <% if(fileSharingStatus.booleanValue()) {
                    // if true, get the name of the files
                    boolean requestSent = new QueryFileNames().getFileNames();
                    if(requestSent) {
                        BufferedReader reader = new BufferedReader(new FileReader(request.getServletContext().getRealPath("/") + Constants.FilePaths.fsPath));
                        String line;
                        while((line = reader.readLine()) != null) {
             %>
                            <%= line %>
                            <br />

            <%
                        }
                    }                        
            } else {
            %>                
                <em>No file has been shared till now !</em>
                 <%}%>
        </td>
    </tr>
</table>

2 个答案:

答案 0 :(得分:1)

错误消息显示“生成的java文件中的行:17处发生错误 令牌“;”上的语法错误,删除此令牌“ - 您将在tomcat的工作目录中找到生成的java文件,并且通常可以从tomcat生成的java代码中识别出有问题的(匹配的)jsp行。

你必须知道jsps执行的方式是,它们被编译成经典的servlet,然后进行字节编码并执行,就像它们是由你编写的一样。由于错误消息适用于生成的某些代码,因此您必须进入该代码。

你有一个额外的多余“;”在你的jsp文件上某处生成一个非法的java servlet - 这就是你在“work”目录中找到的内容

答案 1 :(得分:0)

删除分号:

<%@page import="internet.HelperClasses.*;" %>
<%@page import="General.HelperClasses.*;" %>

<%@page import="internet.HelperClasses.*" %>
<%@page import="General.HelperClasses.*" %>

在生成的 java文件中,上面的代码段为:

import internet.HelperClasses.*;;
import General.HelperClasses.*;;

你看,它会产生错误!