我有一个 JSP 程序,我试图通过使用 xls 中的列动态加载复选框,为此我使用名为JEP的本机库来使用 Python 获取数据。我知道我可以使用 ApachePOI 之类的东西来做相同,但稍后我需要在同一个 Web 应用程序中使用 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:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db032ec8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db033100) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.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:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7a88) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7cc0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 87.626 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x00000000ddf7cb58) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605]
我试图推断可能导致这种情况的原因,但我一无所获。JEP 代码用于生成复选框,效果很好。我尝试使用 sys.out 来调试代码。当我按下按钮时会发生错误,这会导致枚举被填充,此时当检查 while 条件时,JVM 崩溃,ArrayIndex 越界。我尝试使用字符串数组作为表单值,然后使用 .length ArrayUtils.isNotEmpty 方法,这两种方法都不应该抛出该错误。
问题
为什么JVM在崩溃的地方崩溃?如果是 JEP 的问题,它不应该在生成复选框之前崩溃吗?