gpt4 book ai didi

java - 如何在jsp中将数组打印到输入字段?

转载 作者:行者123 更新时间:2023-12-02 05:09:47 26 4
gpt4 key购买 nike

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

[Ljava.lang.String;@678f482d

mem address

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

<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>

FirstFilter.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]

关于java - 如何在jsp中将数组打印到输入字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27427981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com