Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing values from servlets to jsp

 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am new to jsp and i have wriiten a code to access values from servlets to jsp..

kindly tell me what is my mistake???
Reading.jsp


and my servlet is Simpe.java


i have wriiten accessor methods in another class caled Data.java which is not a servlet.......

i am confused whether how do i access values from servlets to jsp...and have I written a proper code to send the data in jsp file??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With all that poorly formatted and unnecessary code, I cannot tell.

Please post again, showing only the code that's necessary to answer your question (how you are setting up the data in the servlet, and consuming it in the JSP) with proper formatting and indentation.
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maggie joseph wrote:hi i am new to jsp and i have wriiten a code to access values from servlets to jsp..

kindly tell me what is my mistake???
Reading.jsp
//this is my jsp which will display the values in a table foramt containing 19 columns...



and my servlet is Simple.java


i have wriiten accessor methods in another class called Data.java which is not a servlet.......


i am confused whether how do i access values from servlets to jsp...and have I written a proper code to send the data in jsp file??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that really how you indent your code?
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir kindly tell me how do i do it???
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put spaces before the first non-space character until elements at the same depth line up. Like this:andSee the difference?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that is not correct. It's easy to tell if it's correct--does it work?
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no its not working.....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see ItDoesntWorkIsUseless and TellTheDetails (those are links).
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you doing this:
Iterator<List> it=b.iterator();
Shouldn't be Iterator<Data> it = b.iterator?
What's b? Is not defined anywhere.
Why do you use the iterator for a list? why not to use just a for(Data myData: request.getAttribute("b"))?
And the most important question... why to use Java code in a JSP where you can use JSTL and EL and forget about iterators, casting, etc...?

Read about the JSTL:

http://java.sun.com/products/jsp/jstl/reference/docs/index.html

and the Unified Expression Language:

http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html

You will see that this:



can be changed to much simpler code:



By the way in your Data class you should have override the method toString, otherwise some strange string will appear in your browser.
 
praneel shah
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use bean...........
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys thanks a lot for your suggestions..it seems that i need to learn a lot still..and i dont know JSTL...

I have changed my code a bit...this is my servlet called Simple.java

and in JSP i have made changes ....i am getting the values of the table but all 4 rows are having same value of the last row.....
How will I get all the values of all the rows..
my jsp Reading.jsp is as follows..it just displays the last row of my database table..I want all 4 rows ..it is displaying same values of the last row in all four rows of my table........
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems okay, although you should close your table row.

INDENT YOUR CODE.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic