JSP无法解析导入java.util.Arrays

时间:2015-04-28 03:41:59

标签: java jsp classpath

这是我的test.jsp代码,我无法通过导入java.util.Arrays来解决错误。为什么?我想把我的数组改为字符串而不是[Ljava.lang.String; @ 71810ee1我是从out.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] 它可以存储在一个字符串中。

1 个答案:

答案 0 :(得分:0)

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

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);
}

无需导入数组:)