File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes fetch only checked data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "fetch only checked data" Watch "fetch only checked data" New topic
Author

fetch only checked data

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

i am retrieving data in the table from the database with the help of jsp servlet , having check box in each row and i want that only checked should be fetch to another page when i click on save button.
please give me some idea howncan i do this , i don't want to delete any data from the database.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

You can get IDs for the checked items, yes? So a SELECT with a WHERE IN seeMs like it would do the job.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Greg Charles wrote:You can get IDs for the checked items, yes? So a SELECT with a WHERE IN seeMs like it would do the job.

but that i have to use when i am selecting from database but here i have to select from the page only without changing anything in database.
i mean i have to call a function on "onclick " event which will going select only checked data and what should be the syntax for that , i want that because i have to apply any functionality which will going to sort data from the database on the page and then redirect me to another page which will going to show those selected data.
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 80
try with this

http://www.redips.net/javascript/sending-checkbox-values/
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225


now when i am trying to redirect my data to next page in the table form it is not redirecting, it is redirecting in the url but ii have to redirect in the table form how should i do that.
Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

So what i assume is that you already have fetched data from the database and created a jsp where the user can check what he/she wants. The next step would be something similar. Just with one little step before it.

1)Send the list of id's to a servlet as shown in the link eshwin provided. Get all the ids from the request parameters in the servlet. I am not sure if you have all the initial data in the session already, but if you dont then query the database again as greg said, SELECT data WHERE id in (<insert all ids you got from servlet parameters>).
2) You will then have all the selected data with you. Create a jsp setting up the format in which you want to display the selected data. Forward the request to a jsp with data in request attributes or session attributes, where inside the JSP iterate over all the data using jstl.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Dhaval J. Patel wrote:So what i assume is that you already have fetched data from the database and created a jsp where the user can check what he/she wants. The next step would be something similar. Just with one little step before it.

1)Send the list of id's to a servlet as shown in the link eshwin provided. Get all the ids from the request parameters in the servlet. I am not sure if you have all the initial data in the session already, but if you dont then query the database again as greg said, SELECT data WHERE id in (<insert all ids you got from servlet parameters>).
2) You will then have all the selected data with you. Create a jsp setting up the format in which you want to display the selected data. Forward the request to a jsp with data in request attributes or session attributes, where inside the JSP iterate over all the data using jstl.

about which ids you are talking, the fields of database or the checkbox id.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Megha Singhal wrote:
Dhaval J. Patel wrote:So what i assume is that you already have fetched data from the database and created a jsp where the user can check what he/she wants. The next step would be something similar. Just with one little step before it.

1)Send the list of id's to a servlet as shown in the link eshwin provided. Get all the ids from the request parameters in the servlet. I am not sure if you have all the initial data in the session already, but if you dont then query the database again as greg said, SELECT data WHERE id in (<insert all ids you got from servlet parameters>).
2) You will then have all the selected data with you. Create a jsp setting up the format in which you want to display the selected data. Forward the request to a jsp with data in request attributes or session attributes, where inside the JSP iterate over all the data using jstl.

about which ids you are talking, the fields of database or the checkbox id.


also i can't use jstl because jstl is not enabled in my college server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

It doesn't need to be enabled by the server. You can just use it in your own web app by dropping the jar files in WEB-INF/lib and using the taglib directives on the views.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

Megha Singhal wrote: about which ids you are talking, the fields of database or the checkbox id.


Its up to you really. Your final aim is to get correct data. Ids you use should be consistent. You cant use random ids for checkbox and then use those ids to query the database, it wont get you the right data and it makes no sense.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Dhaval J. Patel wrote:
Megha Singhal wrote: about which ids you are talking, the fields of database or the checkbox id.


Its up to you really. Your final aim is to get correct data. Ids you use should be consistent. You cant use random ids for checkbox and then use those ids to query the database, it wont get you the right data and it makes no sense.


there is some changes in my requirement , now i want that i am fetching data from the database with corresponding checkboxes in each row but as i am not fetching that into any text boxes so is there any way that i can able to insert only checked data on submission.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Have hidden text field which contains selected item from the list/drop down box and extract value from it when being submitted. This is a simpler idea.


No pain, No gain.
OCJP 1.6
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Kumaravadivel Subramani wrote:Have hidden text field which contains selected item from the list/drop down box and extract value from it when being submitted. This is a simpler idea.


i didn't get what you are saying
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Have an input text field and populate selection value from list/drop down box it when the selection happens, so that when you submit it later and extract as form element in server/where ever needed.
 
GeeCON Prague 2014
 
subject: fetch only checked data