整数数组fibSequence使用如下重定向的重定向传递到jsp页面result<%String[] fibSequence = request.getParameterValues("fibSequence");%>
但是,当我将输入字段的值设置为fibSequence数组时,我得到的是该数组的内存地址,而不是该数组中存储的整数值:

[Ljava.lang.String;@678f482d



这是将数组输出到文本框的方式:

<input type="text" name="fibNum" value="<%=fibSequence%>" size="40px" style="font-size:30pt;height:60px">

而且我已经从下面的答案中尝试过这样,但是输出仍然是相同的:

<input type="text" name="fibNum" value="<%=java.util.Arrays.deepToString(fibSequence)%>" size="40px" style="font-size:30pt;height:60px">

有谁知道如何将数组的内容输出到jsp中的文本框?

我尝试使用Arrays.toString方法打印出值,但出现错误Arrays无法解决:

<%=Arrays.toString(fibSequence)%>

最佳答案

这个例子是可行的:
web.xml

<web-app>
  <display-name>Archetype Created Web Application</display-name>
    <filter>
        <filter-name>filter</filter-name>
        <filter-class>ru.bmstu.FirstFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>filter</filter-name>
        <url-pattern>*</url-pattern>
    </filter-mapping>
</web-app>


FirsFilter.java

...
    void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter from FirstFilter");
        String[] cba = {"1", "2", "3", "5"};
        request.setAttribute("cba", cba);
        filterChain.doFilter(request, response);
    }
...


index.jsp

<%@ page import="java.util.Arrays" %>
<html>
<body>
<h3>This is the JBoss example!</h3>
<% String[] abc = {"1", "2", "3"};%>
<%=Arrays.toString(abc)%>
<% String[] cba = (String[]) request.getAttribute("cba"); %>
<%=Arrays.toString(cba)%>
</body>
</html>


结果是:

This is the JBoss example!
[1, 2, 3] [1, 2, 3, 5]

10-07 22:21