2011-07-28 42 views
-1

在我的Java代码try/catch语句(嵌入在JSP)失败,出现以下错误:的try/catch在JSP失败

An error occurred at line: 26 in the jsp file: /template/tampabay/includes/omniture-footer.jsp 
Syntax error on token "}", delete this token 

我无法确定为什么下面的代码产生错误:

<%! 
    /* 
    * Map the DTI categories to the appropriate SiteCatalyst category 
    * structure. 
    */ 
    ArrayList<HashMap> mapDTIToSiteCatalystCategories(ArrayList<HashMap> dti_categories) { 
     ArrayList<HashMap> site_catalyst_categories = new ArrayList<HashMap>(); 
     ArrayList<Integer> dti_category_ids = new ArrayList<Integer>(); 
     for (int i = 0; i < 4; i++) { 
      try { 
       dti_category_ids.add(Integer.parseInt((String)dti_categories.get(i).get("id"))); 
      } 
      catch (NumberFormatException e) { 
       dti_category_ids.add(-1); 
      } 
     } 
     // - Snip - 
    } 

错误对应于上面的第十二行(try声明的右大括号)。但是,代码在语法上看起来正确。除了通过在JSP中嵌入scriptlet来违反协议,你能帮助指出错误吗?

我尝试过使用此代码的变体(删除for循环并声明单独的变量),但每当我尝试使用try/catch语句时该错误都会持续存在。

EDIT

我上传the complete code listing here.

编辑2: 我还收到以下错误:

An error occurred at line: 44 in the jsp file: /template/tampabay/includes/omniture-footer.jsp 
Syntax error, insert "}" to complete Block 

此错误对应于下面第四行:

   "", "Baseball", 
       "", "" 
     ); 
    break; 
case 120: // Baseball: Minors 
    site_catalyst_categories = addElements(
     dti_category_ids.get(0), "Sports", 

我以前没有包括它,因为我认为它是由较早的错误引起的。但是,根据评论意见,这可能是相关的。

根据我的IDE和我的视觉检查,所有的大括号都正确配对。但是,编译器不同意。

+1

这是正确的,我希望看到的 - 喀嚓 - 部分 –

+0

你用%> –

+3

你为什么要使用小脚本终止你的代码块? :( –

回答

3

它看起来像是在131/132行,try语句有一个缺失的关闭卷曲。

    case 131: 
         try { 
          switch (dti_category_ids.get(2)) { 
           case 252: // Colleges: Bulls ..snip.. 
           case 253: // Colleges: Bulls ..snip.. 
           case 254: // Colleges: Bulls ..snip.. 
           default: // Log all others to the "College" section 
          } 
          break; 
         // HERE ... THERE'S NO } TO CLOSE THE try { 
         catch (NumberFormatException e) { 
          // Log all others to the "College" section 
          site_catalyst_categories = addElements(
            dti_category_ids.get(0), "Sports", 
            "", "College", 
            "", "", 
            "", "" 
           ); 

         } 
+0

良好的眼睛。修复这​​个问题并在218处移除额外的两条线/ 219,问题解决了。谢谢! –

+0

作为一个方面,请尝试使用编辑器将会重新缩进源码。然后你可以告诉它“重新缩进整个文件”,然后查看所有的东西看起来太远了,甚至是所有的东西。我没有使用它,但我过去曾使用过这种功能(适用于各种不同的语言)。 – RHSeeger