• 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

How to display multiple SQL queries on one jsp page using jstl

 
Greenhorn
Posts: 3
  • 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 JSTL and JSP & need some direction on this - preferably and example on how this should be done:

I am running 2 seperate SQL queries from a java/jsp program and I need to display the results from both queries on one JSP page output.

Currently I have java code that passes the 2 queries to a method along with passing the jsp files to output the query results

- the method dispatches the results to these 2 JSP pages using JSTL tags in hope for seperate output results:

I need to have a way to display these 2 outputs into 1 jsp page: - currently one just overwrites the other.
I also tried using the jstl core <c: tags in 2 seperate methods on the same jsp page but the <c: tags just resulted in overwriting one another -

The queries run and display fine except I cannot get them both to display correctly.

I need help on best practice with using jstl and jsp for displaying multiple queries on the same page
please post an example on how this should be done.
thanks! I look forward to any solution on this.

example: the jsp file that runs the queries:

runQuery.jsp:
________________________________________________________________________________________________________________________________________



viewResults1.jsp & viewResults2.jsp
_____________________________________________________________________________

 
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
Welcome to the Ranch.

If you are using JSTL, why do you have Java code in JSPs? Why is runQuery.jsp a JSP at all? Why is all that code not in a Java class?

 
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 should be doing the Java queries under the control of a servlet controller. When the controller has both results, it can forward them to the JSP for creating the view.

I always recommend that newcomers to Servlets and JSp read
  • The Secret Life of JSPs
  • The Front Man


  • The latter gives you an overview of how Java web apps should be structured.
     
    Larry Taylor
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    For expediancy JSTL was a shorcut in writing the table data output to the browser -yes - I could write all this in java classes but thought jstl would shortcut the process for this since it is working with my single queries.

    ...the only problem I am having is handling multiple query output (in this case 2 seperate queries) displaying in one page - i was hoping JSTL could handle that without resorting to writing beans and classes.

    I came from using PHP on most web projects for somthing like this & not an issue there - now forced to use jsp/java/jstl as required of this project. using the JSTL tags seemed to streamline looping the table output

    So - if you have any examples on handling multiple query result output in JSTL (aside from writing more java classes) would be appreciated. Or if there is a subject or post on this please point the way -

    I didn't see anything in the search posts on this subject.

    thanks.
     
    Larry Taylor
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks Bear - I'll read these articles
     
    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

    Larry Taylor wrote:For expediancy JSTL was a shorcut in writing the table data output to the browser -yes - I could write all this in java classes but thought jstl would shortcut the process for this since it is working with my single queries.


    I think you may be confused as to what the JSTL is as the above doesn't make a whole lot of sense. The JSTL is the tag set that you sue in JSPs to make it dynamic. Java code has nothing to do with the JSTL.

    ...the only problem I am having is handling multiple query output (in this case 2 seperate queries) displaying in one page - i was hoping JSTL could handle that without resorting to writing beans and classes.


    No. JSTL is simply to control the JSP page Data access is the realms of Java classes. Mixing Java into a JSP is a practice from over 12 years ago (!!!) and should not be done.

    using the JSTL tags seemed to streamline looping the table output


    Yes, the JSTL is the correct way to write JSP pages.

    So - if you have any examples on handling multiple query result output in JSTL


    Shouldn't be a problem because that's all handled long before the JSP is invoked. Your problem is not the JSTL, but your program structure (or lack thereof).

    You should be getting the data in the controller (preferably delegated to the model layer) and pass it to the JSP. Whether one, two or a bazzillion queries are executed to get the data should have no bearing at all on the JSP.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic