java 如何在jsp页面中打印java String Array。?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16169086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to print java String Array in jsp page.?
提问by Kapil
Hello I am new in jsp i want to print my String array of Java file to My jsp page how to print in web page tell me .. i dont know how to do this.
您好,我是 jsp 新手,我想将 Java 文件的 String 数组打印到我的 jsp 页面 如何在网页中打印告诉我 .. 我不知道该怎么做。
while(rs.next()){
count++;
anArray[i]=rs.getString("subject");
System.out.println(anArray[i]);
i++;
}
while(rs1.next()){
anArray[i]=rs1.getString("subject");
System.out.println(anArray[i]);
i++;
}
回答by CodeChimp
Assuming what you provided is an example of what you want to do in your JSP, the easiest way to do what you are tying to do is to use a JSTL forEach.
假设您提供的是您想要在 JSP 中执行的操作的示例,那么执行您要执行的操作的最简单方法是使用JSTL forEach。
<c:forEach items="${yourArray}" var="myItem" varStatus="myItemStat">
yourArray[${myItemStat.index}] = ${myItem}
</c:forEach>
This assumes you have passed your "yourArray" to the JSP. There are LOTS of tutorials on how to do all of this sprinkled all over the Internet.
这假设您已将“yourArray”传递给 JSP。互联网上散布着大量关于如何完成所有这些工作的教程。
回答by navand
In jsp page you can use this:
在jsp页面中你可以使用这个:
<%
while(rs.next()){
count++;
anArray[i]=rs.getString("subject");
out.println(anArray[i]);
i++;
}
while(rs1.next()){
anArray[i]=rs1.getString("subject");
out.println(anArray[i]);
i++;
}
%>
回答by kark
As i understand your, you are making the output in console , and you are trying to print it in browser.
据我了解,您正在控制台中进行输出,并尝试在浏览器中打印它。
To get the output in browser
在浏览器中获取输出
Just import
the java class in JSP
page
只是页面中import
的java类JSP
In JSP page between tag(<%..%>) by java class object print it in browser,
在 JSP 页面之间的 tag(<%..%>) 由 java 类对象打印在浏览器中,
<%@page import="pack.sample"%>
<%
//In scriplets
Sample obj=new Sample();
String str[]=obj.printMe();//Here printMe() is a fn from Sample class which will return string array
//Now here do all stuffs with str[]
//out.println(str[0]);//It will return zeroth value of str[] in your browser
%>