JSP导入java.util.Arrays不起作用

时间:2015-02-03 16:23:20

标签: java jsp

我在jsp中访问Arrays类时遇到问题。我想创建一个基本页面,列出storeNames参数中的子字符串,即:

http://localhost:8080/JSPExample/index.jsp?storeNames=John,Mary,Gary

应该显示

约翰 玛丽 加里郎

这是我的源代码:

的index.jsp:

<%@ page import="java.util.Arrays,java.util.List" %>

    <html>
    <body>
        This is my first web page
        <%
            String storeNames = request.getParameter("storeNames");
            List<String> namesList = Arrays.asList(storeNames.split(","));
        %>
        <p><b><%= namesList.get(0) %></b></p>
        <p><b><%= namesList.get(1) %></b></p>
        <p><b><%= namesList.get(2) %></b></p>
    </body>
    </html>

以及运行jsp时得到的结果:

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

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

An error occurred at line: 8 in the jsp file: /index.jsp
Arrays cannot be resolved
5:     This is my first web page
6:     <%
7:         String storeNames = request.getParameter("storeNames");
8:         List<String> namesList = Arrays.asList(storeNames.split(","));
9:     %>
10:     <p><b><%= namesList.get(0) %></b></p>
11:     <p><b><%= namesList.get(1) %></b></p>

堆栈跟踪:

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)

我知道使用scriptlet被认为是不好的做法,但现在请告诉我如何解决这个导入问题。

谢谢!

1 个答案:

答案 0 :(得分:-2)

切换到

  

Java-7中的Java-7

作为JBoss的运行环境。
这解决了我的问题。