Reputation: 350
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.
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++;
}
Upvotes: 2
Views: 21175
Reputation: 4853
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
In JSP page between tag(<%..%>) by java class object print it in browser,
<%@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
%>
Upvotes: 2
Reputation: 8154
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.
<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.
Upvotes: 4
Reputation: 476
In jsp page you can use this:
<%
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++;
}
%>
Upvotes: 3