aspose file tools*
The moose likes JSP and the fly likes accessing values from servlets to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "accessing values from servlets to jsp" Watch "accessing values from servlets to jsp" New topic
Author

accessing values from servlets to jsp

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
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

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
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

Joined: Jan 10, 2002
Posts: 60050
    
  65

Is that really how you indent your code?
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
sir kindly tell me how do i do it???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 29, 2008
Posts: 12617

No, that is not correct. It's easy to tell if it's correct--does it work?
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
no its not working.....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please see ItDoesntWorkIsUseless and TellTheDetails (those are links).
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
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

Joined: Mar 16, 2010
Posts: 17
use bean...........
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
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

Joined: Sep 29, 2008
Posts: 12617

Seems okay, although you should close your table row.

INDENT YOUR CODE.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: accessing values from servlets to jsp
 
Similar Threads
how to load the values in one object?
can anyone tell me how do we update the values in servlet?
problem loading jsp from servlets
java.lang.IllegalStateException: Cannot forward after response has been committed
Iterator