• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

accessing values from servlets to jsp

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir kindly tell me how do i do it???
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no its not working.....
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see ItDoesntWorkIsUseless and TellTheDetails (those are links).
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use bean...........
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems okay, although you should close your table row.

INDENT YOUR CODE.
 
You showed up just in time for the waffles! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic