Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Pivot in jsp servlets  RSS feed

 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i'm developing a tracker application in web. everything went fine. But the final stage has to show data in tabular format, the regular tabular format i'm able to generate table like below(by using select * from DB).

Name ID Salary
Ravi 1 10000
Raj 2 10000
Ram 3 20000


But i want to see the reports like below.

Ravi Raj Ram
ID 1 2 3
Salary 10000 10000 20000



some guys suggested me to use pivot tables. but i don't know the concept of. and i'm unable to find a simple reference for this. and i'm using excel as backend and i want to display the reports in my browser. please let me know any simple tutorial where i can learn forming pivot tables in jsp. or any small example explaining so.


Thanks
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're generating HTML, right? And HTML doesn't support pivot tables. So the advice those guys gave you was worthless.

Forget about pivot tables, then, and start working on either something which transforms that data matrix on the server, or some JSP which generates the HTML in that way.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're generating HTML, right? And HTML doesn't support pivot tables. So the advice those guys gave you was worthless.



Hi Paul, thanks for the response, i mentioned the output to be in browser.


i want to display the reports in my browser.



but no where i've mentioned as html. and also the question was about asking ranchers(you guys) for a reference, but not which technology(if i'm not wrong) to be used. Thanks again.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and also this post was posted in jsp page.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm, if not HTML, how do you intend to display in a browser?
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear, Thanks for responding, i want to display in browser using jsps, but not html alone. i just want a reference where i can learn creating these reports.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakesh Keerthi wrote:and also this post was posted in jsp page.

JSP is a templating mechanism for creating HTML. So, you're still using HTML.

So rather than getting snippy with Paul, I suggest you follow his advice. Figure out what the HTML that displays what you want should be, and then write a JSP that produces that HTML.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They key to doing what you want is to structure the data so that it's easy to traverse in the JSP.

So let's start with how this data is structured. List of beans? Other?
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm not using beans. i use jsp, servlets and excel(as backend).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excel. Hmmm. But I thought you said earlier that the data was from a DB?

generate table like below(by using select * from DB).


In any case, I assume you are somehow getting the data out of Excel and into Java structures. What are those structures?

Unless you just plan to let the users download the Excel spreadsheet directly?
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm using just a jdbc(odbc excel driver) connection to get data from excel(which is fine while getting data and i'm able to make a table out of it). but the requirement that i mentioned in my question(was actual requirement that i got) was a bit complicated and i was unable to understand :(
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you are getting the data out of excel and into Java using JDBC.

So when you read the data from the resultset, how are you storing it?
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, Sorry, but i didn't understand your last question. first, i'm inserting data from a webpage into excel and later i'm retrieving the same. this is the process.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakesh Keerthi wrote:and later i'm retrieving the same.

This is what I'm asking about.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear, sorry for delay in response.


I use the below query to get data



and to arrange i use the below


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, good gravy! You're putting Java code in a JSP?

That's a bad practice that has been obsolete for over 12 years. You need to unlearn that bad habit immediately.

You should be fetching the data in a Java class that you can call from the page controller.

Please read this article to understand how modern web applications should be structured. If you're fairly new to JSP, read this article first.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for that Bear. learnt only jsp and servlets :(


But is there a way to get this done in jsps only?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know servlets, then you know Java. So why is the Java code in a JSP and not at least in a servlet? (Doesn't really belong there either, but that's far better than in a JSP.)

I'm not understanding what it is that you "do not know" that's keep you from structuring things properly rather than hacking the code into a JSP.
 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok Bear, thanks for suggestion, i'll make it in servlets and post in same page. Thanks again :)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to read the articles I linked to. You don;t want just change from doing it wrongly one way to doing wrongly in a different way.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!