• 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

Ordered List tag inside jsp

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you can see below I am displaying some employee details using JSP embeded with html tags,
I tried to use html <OL> (ordered list) tag to display the details in ordered way but it not working.

Do i make any mistake or is there any other way?

thanks in advance, sorry if i ask about html in JSP forum!!



 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Refer the below link


HTML Ordered list inside table - 1


HTML Ordered list inside table - 2
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have table. and what you are trying to accomplish by using ol tag with this table?...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch koshan! :)

and Please use code tag while posting your code. this time i have added them for you!
 
koshan koshaa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually i m getting these data from 3 tables using join(sql) operation, but i want to display the row numbers each time i fetch the data from DB,

the row numbers are incremental as it comes from DB, I think this problem can't be solved using HTML.

How to do it using Java Programming logic ?

to display row numbers of the table and increment the row numbers each time the data is fetched from DB.

any help will be appreciated, thanks

[Edit: removed there all-bold text. Please reserve bold for emphasis only.]
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of:

use


it is equivalent, but better :-)
The whole point of jsp is NOT to use java code if at all possible.

This page would benefit from using JSTL rather than scriptlet code, though its not as bad as some I've seen :-)

I don't think list tags and table tags interact very well. Choose one or the other to display what you want.

The structure of a list in html should be <ol><li><li><li></ol>
Your <ol> tags should thus be outside of your loop, and each record in the list should be a <li>
Or
Your <table> tags should be outside of your loop, and each record in the list should be a <tr>

You want to display the current row number on each iteration? Use a variable to keep count (increment by on on each iteration of the loop) or even better, use that JSTL forEach tag and the varStatus attribute.
 
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
It seems that you are working backwards. First, figure out what the valid HTML that you want to display is, then make a JSP that emits that HTML.

And as Stefan pointed out, you should be using JSTL and EL in place of Java scriptlets. Java scriptlets have been outdated and discredited for 10 years now. 10 years! It's time to bring your JSP knowledge out of the dark ages.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, if you need to create a very complex HTML table based on a very complex object data model and if it seems to exceed the capabilities of JSTL or EL, you should create the HTML table in a custom Java Servlet rather than a Java Server Page.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see no way in which emitting HTML in a servlet is easier than using a JSP. Much harder, and certainly messier, in fact.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My post was based on an alternative, not necessarily the what the OP is speaking on. My statements below are about a different type of requirement for a HTML table.

In order to see why it would be better, you would need to also understand the specific complex table requirements and also the specific complex object model. Without this information, it would be very difficult to understand. JSP is not the better option here. Having this type of code in a well-written Servlet class is cleaner and it is easier to understand. The alternative would be a messy mixture of HTML tags and scriptlets in a JSP (much harder to maintain or teach.)

A very complex HTML should be crafted with servlet code. This is a case where the complexity of the requirements and data model surpass the functionality of simple tag libraries of JSTL. JSTL encapsulate "common" functionality. The type of table I'm referring to is not common and the relationships between data is complex. Think multiple iterations of multiple Collections and multiple Maps with nested Lists combined with the required serialized writing of a HTML table, i.e. left to right, row by row.
 
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 have no chance of convincing me that complex HTML is better built up with strings inside Java code than with templating tools. But use whatever works best for you.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Granted that jsp/jtsl can not handle the most complex html you can imagine.

However given that scenario, I can give you two other possible solutions
- use java code to produce a simpler data structure that can be displayed easily on a JSP.
- use a JSP custom tag to handle the display of this complex component, and abstract the complexity away.

it would be a very rare case where I would see the need to have out.println("<html tags>") in a servlet ever again.


 
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

Stefan Evans wrote:- use java code to produce a simpler data structure that can be displayed easily on a JSP.


Ding.Ding.Ding. Give the man a cigar.

Resorting to servlets to generate markup is the last thing to try to do. If you are having trouble consuming a data construct in the JSP, the fault is with the construct, not with JSP.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

- use java code to produce a simpler data structure that can be displayed easily on a JSP.


If this is possible, it certainly is better than scriptlets in JSP or a custom servlet. However, in reality it is possible that such a "simpler" data structure cannot be created. In my example, we are already creating a simplified Presentation data object model from a Storage data object model. The simplified one is still very complex and exceeds the functionality of public tag libraries.

- use a JSP custom tag to handle the display of this complex component, and abstract the complexity away.



This is an option. To handle the complexity mentioned however would require multiple tags, and to get them all to work together would actually be adding complexity, not taking it away. Adding complexity to simply implement a different design is not a good decision, in my opinion. Also, since the tags would never be able to be "reused" in any other type of context, there is little justification for creating a special JSP tag library. Moving the complexity to a tag library is not removing it, it simply is "moving" it and in this case adding extra layers of complexity uneccessarily.

Resorting to servlets to generate markup is the last thing to try to do



True. This would be the last option. It still is an option though. And when that table is generated and viewed in the browser, the customer really doesn't care about how the HTML table was created. The business intelligence derived from the information displayed in the table is the most important thing. Java Servlet imlementations can be very powerful and help realize things that were thought to be not possible.
 
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

Jimmy Clark wrote:it certainly is better than scriptlets in JSP


Hearty agreement! Anything is better than scriptlets in a JSP.
 
reply
    Bookmark Topic Watch Topic
  • New Topic