• Post Reply Bookmark Topic Watch Topic
  • New Topic

display product details from database in a gridview format for online shopping system  RSS feed

 
Bhagyashri Chaudhari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i am new to the forum
I want to display product details such as product image, name, price in a one cell of a table tag on jsp page.

There should be multiple rows and 3 cells per row in the required output


i have written the following code:




This code displays all cells in only one row. I used colspan but its not working....


I have attached the snapshot of above code output and required output

Thank You.


2.png
[Thumbnail for 2.png]
required output file
oooo.png
[Thumbnail for oooo.png]
written code output
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

  • Putting Java code into a JSP is a discredited and obsolete practice that should have been stopped 14 years ago. 14 years! You are writing code that was considered a bad practice a decade and a half ago. Please learn how to write modern JSP using the JSTL and EL.
  • Before even thinking about writing a JSP, design the HTML that you need to display the page correctly. Then, and only then, instrument a JSP to create that markup.
  •  
    Bhagyashri Chaudhari
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok
     
    Mohamed Sanaulla
    Bartender
    Posts: 3174
    34
    Google App Engine Java Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Have a look at http://getbootstrap.com/css/ to arrange your UI in a better way
     
    Bhagyashri Chaudhari
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    will you tell me, what is the mistake and requirement in written code?
     
    Mohamed Sanaulla
    Bartender
    Posts: 3174
    34
    Google App Engine Java Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bhagyashri Chaudhari wrote:will you tell me, what is the mistake and requirement in written code?


    Mixing Java code inside JSP by using Scriplets is BAD practise. Instead make use of Expression Langauge (EL) i.e process the data in your servlet and store it in request and then access the data in your JSP using EL.
     
    Bhagyashri Chaudhari
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i have used servlet to fetched image from database. here is servlet code.





    i try to fetched product details along with image through this servlet but its not working
     
    Stefan Evans
    Bartender
    Posts: 1836
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Remember HTTP is a Request/Response protocol. You send a request to a url, you get back the data. That data might be text, it might be image. It is not normally both.

    So the way you have it right now, producing the HTML in one request (to the JSP) and in that JSP making image tags with links to the servlet is the right way to do it.

    In terms of answering your initial question:
    All of the items are appearing in one row.
    You make a new row with a <tr> tag.
    Obviously your code is not putting the <tr> tag in the right place. How often do you want a new row? Once per database row? Then the <tr> tag should be inside your loop somewhere.
     
    Dave Tolls
    Ranch Hand
    Posts: 2843
    30
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Top tip 1:
    If your layout on the page looks wrong, look at the HTML that has been produced by your JSP as a first step, so you can see where it is wrong (in this case the aforementioned lack of additional <tr>s).
    That will tell you which bit of your JSP you need to look at.

    Top tip 2:
    Having a mocked up HTML page to use as a start point for your JSP is handy. You can then structure your JSP tags around the HTML, and see where your loops should be going.

    :)
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!