• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

how to connect to database and display query vqlus using proper java/jsp

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello there,

dont know if i post this question in the right place but can anyone help me with this:

i am new to jsp and with months of coding i found out that i am doing it the WRONG WAY

and since i dont want to continue doing like that i decided to fix it up.

i have a jsp page here where in everything was just all mixed up (eg : the design and functions)

what i want to do now is to do it properly and that is to
separate the design into the connections and functionalities.
but i dont really know how to start with it.

the class thing i supposed? (please correct me if im wrong)
looking forward for your help and advices. thank you so much. >.<

God Bless you
Posts: 67389
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend novices to JSP read the following articles:
  • The Secret Life of JSPs
  • The Front Man

  • The first will make sure that you understand what JSP is, and how it operates.

    The second will answer your question regarding proper web application structure.

    And above all, remember to keep Java code out of the JSP.
    khamhielle gabriel
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hello Bear Bibeault, :)

    i really appreciate the articles you have shown me.
    and it did help me to understand some things about jsp .
    and its great.

    but the thing is, i still dont know how to get started with
    the question i ask a while ago.

    how to connect to database and display query values using proper java/jsp?

    and now i was eager more to learn how .

    super thanks.

    God Bless you.
    Ranch Hand
    Posts: 89
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi khamhielle,
    You need to separate the presentation from business logic.. Here is a simple how
    You need a servlet (say DisplayController.java)
    You need a JSP (MyView.jsp)
    Then..through your web browser.. you should call the servlet (assuming you have configured the servlet in web.xml)
    In the servlet, you will retrieve the contents from database and put the contents in a list or map or any data structure of your choice. Then you need to get that variable ready to be accessible by UI. That means you should send the variable by adding it at as an attribute to the request.

    Then pass on the view to JSP. You can do that by using the RequestDispatcher

    In JSP you should use your scriptlets/JSTL to just iterate over the results variable that is retreived from attributes which is a list or or map and display them

    Hope its clear.. Can ask if its not!
    A teeny tiny vulgar attempt to get you to buy our stuff
    Two software engineers solve most of the world's problems in one K&R sized book
      Bookmark Topic Watch Topic
    • New Topic