I'm having trouble accessing the Arrays class in a jsp. I want to make a basic page that lists the substrings in the storeNames parameter, i.e.:
http://localhost:8080/JSPExample/index.jsp?storeNames=John,Mary,Gary
should show
John
Mary
Gary
Here is my source code:
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>
and what i get when running the 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:
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)
I know using scriptlets is considered bad practice, but for now just please tell me how i can resolve this import problem.
Thank you!