This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I move to last record of database with a button in JSP, using JavaScript function  RSS feed

 
danny ramdayal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have created a code that display database record into a html textbox and I am able to move to the next record and move back a record using a javascript function that I assign to a button. but i having trouble creating a function that will allow me to move to the last record and a button to move back to the first record.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before we even get to the JavaScript, your page has some serious problems. First and foremost it will break badly when more than one user starts to use your application because you have used scriptlet declarations within the page.

One of the very many reasons that scriptlets were obsoleted and discredited over 12 years ago was just this very type of problem. Java code should be in a Java class and never in a JSP.

I can tell from the way that you've written your HTML, JavaScript, and other elements that you are using some very old references. I'd highly advise adopting more recent reference material.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, even supposing all that was in a Java class, there is still a problem. The query is being done each time so it doesn't make sense to talk about going to the first/last part. It would make sense to have a button control the sorting or paging of the result. Which would be passed to the query to change/limit the results.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the sort of thing that DataTables was made for. And Bear and Jeanne are offering you critical advice; pay heed. You are headed down a long, ugly road with the style of coding that you are using. Your jsp should end up looking something like this:


This is just an example from one of my pages; it's not meant to address your question directly. But notice that there are no scriplets and no database functions in the page. All that belongs at another layer. A servlet calls a DAO which manages the database functions. Jquery, AJAX and DataTables build the page components and insert them when and where needed. A different servlet handles exporting to Excel.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!