File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Help in iterating array from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Help in iterating array from jsp" Watch "Help in iterating array from jsp" New topic
Author

Help in iterating array from jsp

Caleb Jhay
Greenhorn

Joined: Apr 13, 2011
Posts: 18

Hi guys I dont know where to post this question and I'm new in this forum. I have a problem iterating an array in jsp below is my code. I'm trying to iterate and write the value of a on my javascript and it doesnt work. Been doing this for almost 2 days and I'm kinda new to this stuff. I want to print the value of a using javascript so any help is pretty welcome.



Regards
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Welcome to the Ranch!

There are a number of really big, really fundamental problems here.

Firstly, if you are just starting off, you are already a decade behind the times! It is no longer acceptable to put Java code and Java scriptlets in a JSP. That is a bad bad practice that has been discredited since 2002!

Also, you can't just mix server-side code and client-side JavaScript and expect them to mix. They're not running at the same time or even on the same system.

Do yourself a favor and learn to write JSP the correct and modern way with the JSTL and EL in place of discredited scriptlets.

With regards to understanding fundamentals, please read this article. When you a done with that one, this article will outline how to properly structure web applications.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Of particular note, in the following line of code:you are apparently expecting some sort of magic to happen to transform a Java structure into a JavaScript structure. After reading the first article linked above, you'll see why this simply cannot work.

In fact, do a View Source in the browser to see what's being delivered to it. Does it make any sense. (Hint: answer is "no")

After reading the articles, you'll should understand the concept of "template text" and how to use it to set up the data such that it can be used from JavaScript.

And of course,using modern JSTL and EL in place of Java scriptlets.
Caleb Jhay
Greenhorn

Joined: Apr 13, 2011
Posts: 18

Bear Bibeault wrote:Welcome to the Ranch!

There are a number of really big, really fundamental problems here.

Firstly, if you are just starting off, you are already a decade behind the times! It is no longer acceptable to put Java code and Java scriptlets in a JSP. That is a bad bad practice that has been discredited since 2002!

Also, you can't just mix server-side code and client-side JavaScript and expect them to mix. They're not running at the same time or even on the same system.

Do yourself a favor and learn to write JSP the correct and modern way with the JSTL and EL in place of discredited scriptlets.

With regards to understanding fundamentals, please read this article. When you a done with that one, this article will outline how to properly structure web applications.


Thank you for your reply. First of all this is not my code. This project was done few years ago and I was just asked to debug some problem. Second I'm not really a java programmer thats why I know nothing about this stuff. The thing is the existing jsp code is connected to database and it has a query that select records from the database. I was asked to pass some parameter in the query and that parameter will came from a text box in the jsp. I know it is possible by submitting the page and doing this transaction inside the controller or by ajax. but right now studying java and the project framework is not an option to me because time is the luxury that I dont have. The only solution that I'm thingking right now is to iterate a java array inside javascript.

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Surely you have time to read a few articles?
nithin chinni
Ranch Hand

Joined: Dec 02, 2010
Posts: 41
Caleb Jhay wrote:Hi guys I dont know where to post this question and I'm new in this forum. I have a problem iterating an array in jsp below is my code. I'm trying to iterate and write the value of a on my javascript and it doesnt work. Been doing this for almost 2 days and I'm kinda new to this stuff. I want to print the value of a using javascript so any help is pretty welcome.



Regards


Okay this should work fine.
<html>
<head>
<title>testing</title>
</head>
<body>
<table>
<%
String a[] = {"January", "Febuary", "March"};
for(i=0;i<3;i++)
{ %>
<tr><td><%=a[i]%></td></tr><%
}


%>
</body>
</html>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help in iterating array from jsp