This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

need help with a logic

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

I need your help in figuring out a solution for a problem.
I have a table on jsp (Snapshot), According to a new requirement:

All the cells where value is less than 100%, those numbers should be an HTML link. I guess
I can figure out a way to do this, the problem I am facing is, on clicking any of these links,
the control needs to be directed to a specific page related to that cells application (First Column)

now how do I know figure out a way to know what cell user actually clicked. one way I could think
is is passing parameters along with the link, but then again, how do I assign these parameters to every cell.?
Table.PNG
[Thumbnail for Table.PNG]
snapshot
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how you generate your table, but I guess you have 2 loops. loop 1 writes the rows, and loop 2 the cells.

So, when you enter loop 1, set a flag which application you're at right now. Upon looping the cells, you can pick up on it.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Sebastian

I am fairly new to this. Could you please tell me how do I set a flag? This is the code I am using to generate the table.

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


rs.getString(1) holds the current application, store it right after that so you can pick it up in the other loop.

Also, are you sure you don't want to move your java code into a servlet instead? This looks horrid.
 
Marshal
Posts: 67340
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doing JDBC in a JSP? In 2009?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you creating dynamic table that time you can generate link with the value (here i am asuming pk) and by that pk on link you can do your rest of logic.

something like this

[url][/url]

when you will click on link you can get value (pk) on new page and by that keyvalue you can do rest of your logic.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sebastian,

Thanks for the reply, though it went over my head, i will try my best to mess with it :-)

I know that JSP looks horrible, but I am not sure, how I will write all that code in a Servlet and then use in my JSP
 
Bear Bibeault
Marshal
Posts: 67340
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JDBC should not even be done in a servlet. Rather a model-layer class should gather the data, put it into a normal Java collection, and pass it onto the servlet controller to be passed to the JSP.

There, use the JSTL and EL to render the table.

You might find this article on properly structuring web applications helpful.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Bear,

very very new to this trying my level best to learn as much as I can from people like you.

@ Ranveer,

Did you try to put any code? if yes, then I cant see anything
 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Doing JDBC in a JSP? In 2009?



May be they doing very small project or just for learning purpose
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes Ranveer,

Its a very small project.
 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

@ Ranveer,

Did you try to put any code? if yes, then I cant see anything



yes but link is truncated so again i edited with ahref instead of a href you can understand
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help folks

Ranveer now its making sense to me :-) sorry for acting so dumb.

But this dynamic value would be the same for complete row right?
 
Bear Bibeault
Marshal
Posts: 67340
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ranveer K Kumar wrote:May be they doing very small project or just for learning purpose


That's no excuse. Learning bad habits, even for a small project is not a great idea. And learning bad habits is not a good "learning purpose".

Besides, small projects have a habit of becoming big projects, and then you're stuck with the mistakes you made at the outset.

My advice is to use good practices always.
 
Bear Bibeault
Marshal
Posts: 67340
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aman Singh wrote:trying my level best to learn as much as I can from people like you.


Then my advice, like I said, is to develop good habits and good practices right off the bat.

Never put Java code into a JSP. That's a practice that was discredited over 6 years ago with advent of JSP 2.0.

And learn how to properly construct web applications and always follow that structure. Even for very small projects. It's a good learning experience, and if the project turns out to grow, you've already got a good base to build upon.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, Ranveer, Sabsatian,

I will surely start reading more on Servlets and jsps. Will bug you guys more with my doubts :-)
 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
That's no excuse. Learning bad habits, even for a small project is not a great idea. And learning bad habits is not a good "learning purpose".
Besides, small projects have a habit of becoming big projects, and then you're stuck with the mistakes you made at the outset.
My advice is to use good practices always.



@ Bear
Yes I am completely agree with you..
 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aman Singh wrote:Thanks for the help folks

Ranveer now its making sense to me :-) sorry for acting so dumb.

But this dynamic value would be the same for complete row right?



It depends on requirement. But as every column has unique data so you can implement this on column base..
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!