JSP中在html插入java代码,执行时一直报错

JSP中在html插入java代码,执行时一直报错,如图:
图片说明

<%@page import="com.matrixone.apps.program.ProgramCentralConstants"%>
<%@include file = "../emxUICommonAppInclude.inc"%>
<%@page import = "com.matrixone.apps.domain.*"%>
<%@include file = "../common/emxUIConstantsInclude.inc"%>
<%@include file = "../emxStyleDefaultInclude.inc"%>
<%@page import="com.matrixone.apps.domain.DomainObject"%>
<%@page import="com.matrixone.apps.domain.util.MapList"%>
<%@page import="matrix.db.Context"%>
<%@page import="matrix.util.StringList"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%!
        MapList list1 = new MapList();
        MapList list2 = new MapList();
        MapList list3 = new MapList();
        MapList list4 = new MapList();
        StringList busSelects1 = null;
        StringList busSelects2 = null;
        StringList busSelects3 = null;
        StringList busSelects4 = null;
        String whereExpression1 = null;
        String whereExpression2 = null;
        String whereExpression3 = null;
        String whereExpression4 = null;
        int num1 = 0;
        int num2 = 0;
        int num3 = 0;
        int num4 = 0;
        int total = 0;
        int count = 0;
        int[] num = null;
        String titleText = null;
        String name1 = null;
        String name2 = null;
        String name3 = null;
        String name4 = null;
        String[] nameJs = null;
%>

<HTML>
    <HEAD>
        <%
        String value = request.getParameter("plugin");
        if("test2".equalsIgnoreCase(value)){
        titleText = "标准化等级分析";
        num = new int[3];
        //gnssStandardizedGrade = Component_commonality
        whereExpression1 = "(attribute[gnssStandardizedGrade]=='Component_commonality') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects1 = new StringList(1);
          busSelects1.add(DomainObject.SELECT_ID);

          list1 = DomainObject.findObjects(context, null, null, whereExpression1, busSelects1);
          num1 = list1.size();
          name1 = "通用件";
          num[0] = num1;

//gnssStandardizedGrade = Standard_component

          whereExpression2 = "(attribute[gnssStandardizedGrade]=='Standard_component') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects2 = new StringList(1);
          busSelects2.add(DomainObject.SELECT_ID);

          list2 = DomainObject.findObjects(context, null, null, whereExpression2, busSelects2);
          num2 = list2.size();
          name2 = "标准件";
          num[1] = num2;
//gnssStandardizedGrade = Special_purpose_item

          whereExpression3 = "(attribute[gnssStandardizedGrade]=='Special_purpose_item') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects3 = new StringList(1);
          busSelects3.add(DomainObject.SELECT_ID);

          list3 = DomainObject.findObjects(context, null, null, whereExpression3, busSelects3);
          num3 = list3.size();
          name3 = "专用件";
          num[2] = num3;

          num4 = 0;
          nameJs = new String[]{"通用件","标准件","专用件"};
          count = 3;


        }else if ("test1".equalsIgnoreCase(value)){
        titleText = "优选等级分析";
        num = new int[4];

         whereExpression1 = "(attribute[gnssPreferredLevel]=='Preferred') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects1 = new StringList(1);
          busSelects1.add(DomainObject.SELECT_ID);

          list1 = DomainObject.findObjects(context, null, null, whereExpression1, busSelects1);
          num1 = list1.size();
          name1 = "优选";
          num[0] = num1;

  // gnssPreferredLevel=Limited

          whereExpression2 = "(attribute[gnssPreferredLevel]=='Limited') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects2 = new StringList(1);
          busSelects2.add(DomainObject.SELECT_ID);

          list2 = DomainObject.findObjects(context, null, null, whereExpression2, busSelects2);
          num2 = list2.size();
          name2 = "限选";
          num[1] = num2;

  // gnssPreferredLevel=Banned

          whereExpression3 = "(attribute[gnssPreferredLevel]=='Prohibition') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects3 = new StringList(1);
          busSelects3.add(DomainObject.SELECT_ID);

          list3 = DomainObject.findObjects(context, null, null, whereExpression3, busSelects3);
          num3 = list3.size();
          name3 = "禁采";
          num[2] = num3;

  // gnssPreferredLevel=Prohibition

          whereExpression4 = "(attribute[gnssPreferredLevel]=='Banned') && (type=='gnssMaterialPart'||type=='gnssSemiFProductPart') && (current!='Obsolete')";
          busSelects4 = new StringList(1);
          busSelects4.add(DomainObject.SELECT_ID);

          list4 = DomainObject.findObjects(context, null, null, whereExpression4, busSelects4);
          num4 = list4.size();
          name4 = "禁选";
          num[3] = num4;
          nameJs = new String[]{"优选","限选","禁采","禁选"};
          count = 4;

        }
      }
      total = num1+num2+num3+num4;
      %>

        <script type="text/javascript" src="../common/scripts/jquery-latest.js"></script>
        <script type="text/javascript" src="../plugins/highchart/3.0.2/js/highcharts.js"></script>
        <script type="text/javascript" src="../plugins/highchart/3.0.2/js/modules/exporting.js"></script>
        <script type="text/javascript" src="scripts/styleCharts.js"></script>

        <script>

          var gnssStandardizedGradeAnalyse;

           $(document).ready(function() {

          gnssStandardizedGradeAnalyse = new Highcharts.Chart({
               chart: {
                   renderTo: 'gnssStandardizedGradeAnalyse',
                   plotBackgroundColor: null,
                   plotBorderWidth: null,
                   plotShadow: false
               },
               title: {
                  text: '<%=titleText%>'
               },
               tooltip: {
                  pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>',
                  formatter: function() {
                    return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +'% ('+
                    Highcharts.numberFormat(this.y, 0, ',') +' \u4E2A)';
                  }
               },
               plotOptions: {
                  pie: {
                     allowPointSelect: true,
                     cursor: 'pointer',
                     dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                     },
                     formatter: function() {
                        if (this.percentage > 4) return this.point.name;
                      },
                     showInLegend: true
                  }
               },
               credits: {
                   enabled : false
               },
               exporting:{
                   enabled : false
               },
               series: [{
                  type: 'pie',
                  name: '\u5360\u6BD4',
                  data: [
                     ['<%=name1%>',   <%=num1%>],
                     ['<%=name2%>',   <%=num2%>],
                     {
                        name: '<%=name3%>',
                        y: <%=num3%>,
                        sliced: true,
                        selected: true
                     },
                     ['<%=name4%>',   <%=num4%>],
                  ]
               }]
              });
            });

        </script>

    </HEAD>
    <body>
        <!--<div id="gnssOptimumLevelAnalyse" style="width: 550px; height: 400px; margin: 0 auto; float: left"></div>-->
          <div id="gnssStandardizedGradeAnalyse" style="width: 550px; height: 400px; margin: 0 auto; float: left"></div>
        <!--<div id="gnssKeyItemAnalyse" style="width: 550px; height: 400px; margin: 0 auto; float: left"></div>-->
          <table border="1" align="center">
            <tr>
              <td align="center">名称</td>
              <td align="center">数量</td>
            </tr>
            <%
              for(int i=0;i<nameJs.length;i++){
             %>
            <tr>
              <td align="center"><%=i%></td>
              <td align="center"><%=nameJs[i]%></td>
            </tr>
            <%}%>
        </table>
        <!--<p><%=name1%>数量:<%=num1%> pcs</p><br>
        <p><%=name2%>数量:<%=num2%> pcs</p><br>
        <p><%=name3%>数量:<%=num3%> pcs</p><br>
        <p><%=name4%>数量:<%=num4%> pcs</p><br>-->
        <b>合计数量:<%=total%> pcs</b><br><br>
        <form id="test" method="post" action="gnssTest.jsp">
        <select id="mySelect" name="plugin" onchange="a(this)">
          <option value="test2">标准化等级分析</option>
          <option value="test1">优选等级分析</option>
          <option value="test3">管控等级分析</option>
        </select>
        <input id="change" type="submit" value="提交"/><br>
        </form>
    </body>
</HTML>

tiankongzhichenglyf
tkzc_shark 有意思?
6 个月之前 回复

2个回答

nameJs 在 Java 指令中没有覆盖所有的分支,导致存在 nameJs 为空的情况,根据你的代码情况,能否设置一下默认值呢?

qq_41287297
qq_41287297 不好意思,我搞错了,问题解决啦,十分感谢大神
6 个月之前 回复
qq_41287297
qq_41287297 设置初始值后报这个错误:An error occurred at line: 262 in the jsp file: /common/gnssTest.jsp name.length cannot be resolved to a type 259: <td align="center">??</td> 260: </tr> 261: <% 262: for(int i=0;i<name.length;i++){ 263: %> 264: <tr> 265: <td align="center"><%=i%></td>
6 个月之前 回复
 for(int i=0;i<nameJs.length;i++){

int改为var

tiankongzhichenglyf
tkzc_shark 回复qq_41287297: nameJs为空了,循环外层判断一下
6 个月之前 回复
qq_41287297
qq_41287297 不行,这个for循环是java代码
6 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问