jsp无法解析导入java.util.arrays

shstlldc  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(456)

这是我的test.jsp代码,我无法通过导入java.util.arrays来解决错误。为什么?我想把数组改成string而不是[ljava.lang.string@71810ee1,我从外面得到的。println(a);。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.Arrays" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% String[] a = request.getParameterValues("multiple");
if(a!=null)
{
    String res = Arrays.toString(a);
    out.println(res);
    //out.println(Arrays.toString(a));
for(int i=0;i<a.length;i++){
//out.println(Integer.parseInt(a[i])); //If integer
%></br><%
out.println(a[i]);
}}
%>
<html>
<body>
<form action="test.jsp" method="get">
<select name="multiple" multiple="multiple"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input type="submit">
</form>
</body>
</html>

我的错误:

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

An error occurred at line: 7 in the generated java file
The import java.util.Arrays cannot be resolved

An error occurred at line: 13 in the jsp file: /test.jsp
Arrays cannot be resolved

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

我当前的结果是1 2 3我想要的结果是[1,2,3],它可以存储在一个字符串中。

okxuctiv

okxuctiv1#

终于解决了。对于那些想和我一样的人。

if(a!=null)
{

for(int i=0;i<a.length;i++){
//out.println(Integer.parseInt(a[i])); //If integer
//out.println(a[i]);
value += a[i]+" ";

}
out.println(value);
}

无需导入数组:)

相关问题