• 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

Pass data to JSP page

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this topic (javaranch) and this topic (SDN) while learning how to pass my sql result (which was changed to an ArrayList, so I can close the connection) to a jsp page.

Currently I have a servlet method that queries mysql. The jsp page calls the method as such:


Am I approaching this correctly? If not can you provide me with some sites to read?

I also found MVC example or tutorial, but I still need advice for outputting a mysql result to a jsp page.
[ July 05, 2008: Message edited by: ranchaz ]
 
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
"ranchaz", please check your private messages for an important administrative matter.
 
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
No. All code having to do with SQL should be as far removed from the UI as possible, and not be anywhere near a JSP page.

Your page controller should call methods in your model classes to obtain the results. As you read in the other topics, the results should not be still ensconced in the JDBC resultset, but copied to other collection types.
 
Blaine Swensen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
No. All code having to do with SQL should be as far removed from the UI as possible, and not be anywhere near a JSP page.



So where can I find information on the proper placement of an SQL connection?
I would greatly appreciate an example diagram, war file, or description.

Originally posted by Bear Bibeault:
Your page controller should call methods in your model classes to obtain the results. As you read in the other topics, the results should not be still ensconced in the JDBC resultset, but copied to other collection types.



How I understand the mvc process currently is..
A client makes a request to a servlet >
The servlet (Page/Task Controller) operates on the request and gathers the necessary data to output >
The servlet sends that data (via unknown means-Still Learning) to jsp >
Server sends JSP response with the data the servlet sent to it.

I've been reading Scriptless JSP Pages: The Front Man but I am not familiar with what a java bean is, how it differs from a servlet, or how my servlet would interact with it, as well as how my servlet should interact with the jsp page.

I have, however understood that I should copy the resultset so I may close the connection. I use an ArrayList of Maps for rows & columns.
[ July 05, 2008: Message edited by: Blaine Swensen ]
 
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

Originally posted by Blaine Swensen:
The servlet (Page/Task Controller) operates on the request and gathers the necessary data to output

Yes. but it also delegates to the model layer to perform operations on the model. All JDBC should be ensconced in the model layer.

The servlet sends that data (via unknown means-Still Learning) to jsp

The servlet usually sets scoped variables into request or session scope via the setAttribute() methods.

Server sends JSP response with the data the servlet sent to it.

Not quite. The JSP is executed to create the plain HTML response that is sent to the browser. JSP is a server-side concept.

but I am not familiar with what a java bean is, how it differs from a servlet

Beans are an important Java concept that you need to have under your belt before diving off into JSP and servlets. Essentially a bean is a Java class that follows certain conventions that make them easy to deal with in reflective fashion. Primarily they contain properties that can be set or accessed using methods whose signature follow the JavaBean standard.

I have, however understood that I should copy the resultset so I may close the connection. I use an ArrayList of Maps for rows & columns.

Good start!
 
Blaine Swensen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've reviewed a couple sample applications SimpleTable and SimpleMVC and I see how java beans work and how the MVC interacts. I would like more information on the usage of java beans. Do you have any good information on the topic? I feel like Trail: JavaBeans(TM) is lacking in content related to web applications. Maybe I am not looking in the right places.

Thank you very much for your help so far!
[ July 06, 2008: Message edited by: Blaine Swensen ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Blaine Swensen:
I would like more information on the usage of java beans. Do you have any good information on the topic?



Check out the chapter "Using JavaBeans Components in JSP Documents here.
 
Blaine Swensen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, now that I see how they are used and I read the chapter it makes perfect sense. Now that I understand bean basics I want to use beans!
I understand how to retrieve data of which I know the structure. I would have an accessor for each column.
I don't understand how I would retrieve a data set that relates to another data set.
Using Cattle Drive - Servlets - Videos as an example, I would know the title, star, etc., but I would want to also add a list of supporting actors of an unknown quantity, and have a dynamic type/genre list.
Using the Videos (now JDBC) as an example, I would imagine having a table of videos as such...

and also a table of supporting actors...

and a table of genres...


I would expect my JDBC model layer to retrieve the video, look for `SuppActors` of Video #, and then get the `TYPE` of video from `Genres`. I know what queries I would use, but to output that, is beyond me at this point.
[ July 06, 2008: Message edited by: Blaine Swensen ]
 
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
Now you are into the realm of object modeling.
 
Blaine Swensen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There doesn't seem to be much on the topic. I found this but it seems short for what we are talking about.

Thanks for the help! You've really pointed me in the right direction!
[ July 07, 2008: Message edited by: Blaine Swensen ]
 
Blaine Swensen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know of any additional information about model objects?
 
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
What you've posted translates to beans fairly easily.

Obviously, you'd have a Video bean, with discrete members to represent scalar values like title and description.

And a List element to represent Genre (perhaps as a list of Strings, or of Genre instances), and a List of Actor instances for supporting actors.

(Personally, I'd have made made "star" a reference into the Actors table. I'd also have a Type table that translates the magic numbers to human-readable strings.)

Here's a rough first pass (assumes foreign ref for star):
[ July 07, 2008: Message edited by: Bear Bibeault ]
 
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
You might want to read up on ORM (or gander at the ORM forum here) even if you don't plan to use an ORM tool such as Hibernate. There's a lot of information on Relational-->Object modeling to be had there.
[ July 07, 2008: Message edited by: Bear Bibeault ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic