in the above code i use getAttribute(("customername") in my jsp to get the value.. i ll be getting the result only once from the database.. but i ve more than 10 data in my "name" column ... what is the code to iterate and get all the 10 data in my jsp.. ?? please help me out... thanks in advance..
Ashwin please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it.
I don't see this question has anything to do with struts (it uses struts but the question isn't about struts). You need to create an array of Strings instead of a single string result i.e. instead of String result=null;, you need String result=null; or better use List<String> result = new ArrayList<String>();. Assuming that you'll use ArrayList, you'll need to change your while loop to something like this
That's it, now you just have to iterate over the ArrayList in your JSP and display the elements. You can do it using JSTL forEach tag...
ashwin bala wrote:Thanks a lot Mr.Aditya ... but y should not i use scriplets inside jsp when using struts..? i had to use getAttribute().. what is the problem in using it?
Ashwin, please UseRealWords on javaranch. Don't use abbreviations like "y" or "r" etc. Using scriptlet in JSP pages is considered very bad practice. It makes the pages mostly unmanageable and hard to maintain. Aditya showed you how you can achieve the same behavior without using scriptlet. Since you are using struts, so all your logic would be outside of your JSP, so you should not face any condition where you need to use scriptlet in your JSP...
Joined: Dec 07, 2009
Thanks again... Mr.ankit .Iam in learning curve of struts .Please help me with this issue as well. In this code i have retrieved only one column that is the company name
but i need to add other column that is "companyaddress"...How should i add that to arraylist..?
and how can i retrieve that in my jsp? is that same procedure?