>我有一个JSP程序,我试图通过使用xls中的列动态加载复选框,为此我使用一个名为JEP的本机库来使用Python来获取数据。我知道我可以使用像ApachePOI这样的东西来做同样的事情,但我稍后需要在同一个网络应用程序中使用JEP。
复选框的 JSP:
<%@ page import ="Excel.getCSV" %>
<%@page import = "java.util.ArrayList " %>
<% ArrayList<String> columns = new ArrayList<String>();
columns= getCSV.columnGetter();
//String hobbies[];
for(int i=0;i<columns.size();i++){ String str= columns.get(i);
%> <li class="mdl-list__item">
<input type="checkbox" name="hobbies[]" id="hobby1" value= <%= str %> />
<%= str %> <!-- all of this works -->
</li>
处理表单数据
<%@ page import = "java.io.*,java.util.*" %>
<%@ page import ="org.apache.commons.lang3.ArrayUtils" %>
<%
String[] form = {"asda","asd"};
//form = request.getParameterValues("hobbies[]"); I have tried using
//ArrayUtils.isNotEmpty instead of using the enum
System.out.println("I am here"); //This works
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
System.out.println("I actually reached here");// Crashes before printing
this.
%>
<jsp:forward page = "Page3.jsp" /><%
<% }
%>
列获取器代码:
public static ArrayList<String> columnGetter() throws JepException {
try(Jep jep = new Jep()) {
jep.set("pathToPython", path);
jep.eval("from foo import getColumn");
jep.eval("x= getColumn(pathToPython,1)");
names=(ArrayList<String>) jep.getValue("x");
jep.close();
}
return names;}
JVM 崩溃并显示以下错误:
#The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
所以我删除了本机代码(JEP 代码(,程序可以工作。
问题所在
避免使用本机代码不是解决方案。所以我看到了错误日志,根据它有一个"ArrayIndexOutOfBoundsException"
Internal exceptions (10 events):
Event: 16.868 Thread 0x000000001ec47000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000dacc0b00) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db032ec8) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db033100) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 17.232 Thread 0x000000001b19d000 Implicit null exception at 0x000000000534ebb1 to 0x00000000053512e1
Event: 17.271 Thread 0x000000001b19d000 Implicit null exception at 0x0000000004ec1ead to 0x0000000004ec4159
Event: 17.272 Thread 0x000000001b19d000 Implicit null exception at 0x0000000004cae411 to 0x0000000004cae849
Event: 17.611 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': 10604> (0x00000000d6608708) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7a88) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7cc0) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 87.626 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x00000000ddf7cb58) thrown at [C:reworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevmruntimesharedRuntime.cpp, line 605]
我试图推断出可能是什么原因造成的,结果我空手而归。JEP代码用于生成复选框,工作正常。我尝试使用 sys.out 来调试代码。当我按下按钮时会发生错误,这会导致枚举被填充,此时当检查 while 条件时,JVM 崩溃,ArrayIndex 越界。 我尝试使用字符串数组作为表单值,然后使用.length ArrayUtils.isNotEmpty方法,这两种方法都不应该引发该错误。
问题
为什么 JVM 在崩溃的地方崩溃?如果是JEP的问题,它不应该在生成复选框之前崩溃吗?
嗯,我找到了原因。我不知道为什么日志中的错误是 Arrayindexoutofbounds,但发生错误是因为我的 JEP 库位于我的类无法访问的文件夹中。