如何打印数组在JSP输入字段? [英] How to print an array to an input field in jsp?
问题描述
整数数组 fibSequence
被传递到一个JSP页面结果
使用的是类似这样的检索重定向:<%的String [] = fibSequence request.getParameterValues(fibSequence);%GT;
。
但是,当我输入字段的值设置为fibSequence阵列我得到的阵列的存储器地址,而不是存储在数组中的整数值:
An array of integers fibSequence
is passed over to a jsp page result
using a redirect which is retrieved like this: <%String[] fibSequence = request.getParameterValues("fibSequence");%>
.
But when I set the input field's value to the fibSequence array I get a memory address of the array and not the integer values stored in the array:
[Ljava.lang.String; @ 678f482d
这就是数组是如何被输出到文本框:
This is how the array is being output to the text box:
&LT;输入类型=文本名称=fibNumVALUE =&LT;%= fibSequence%GT;大小=40像素的风格=FONT-SIZE:30pt;高度:60像素&GT;
和还我试着像这样从下面的答案,但输出仍然是相同的:
and also I've tried like this from the below answer but the output is still the same:
&LT;输入类型=文本名称=fibNumVALUE =&LT;%= java.util.Arrays.deepToString(fibSequence)%GT;大小=40像素的风格=FONT-SIZE:30pt;高度:60像素&GT;
有谁知道数组中的内容如何可以输出到一个文本框在JSP中?
Does anyone know how the contents of the array can be output to a textbox in jsp?
我曾尝试使用Arrays.toString方法打印出来的值,但我得到一个错误阵列
不能被解析:
I have tried to use the Arrays.toString method to print out the values, but I get an error Arrays
cannot be resolved:
&LT;%= Arrays.toString(fibSequence)%GT;
推荐答案
此示例工作:
的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
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的
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]
这篇关于如何打印数组在JSP输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!