Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes crating a table using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "crating a table using JSP" Watch "crating a table using JSP" New topic
Author

crating a table using JSP

abhishek rathur
Ranch Hand

Joined: Jan 14, 2010
Posts: 66
I am creating a web application in which there is a table which gets values from database, what i need is to select one of the table value and pass it to another form.
things i am looking for
1.How to select a data from the table.
2.How to send the selected data to other form.
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Hi,

which database you are using oracle or mysql.
According to that you have to create one java file to establish connection with database.
You have to know some basic knowledge in jdbc.
Basic example is here just click this Link
Regards,
Sriram.V


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
abhishek rathur
Ranch Hand

Joined: Jan 14, 2010
Posts: 66
thank you Sri for replying
I am using Mysql,i have done my connectivity using JDBC and its working,what i need is to select one of the values from the table and pass that value to another form.
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Okay i am giving the sample code and change it accordingly.


Mostly bean is used to set the value and you can get the bean value in action file.
Let me know if you have any more query.

Regards,
Sriram.V
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
1.How to select a data from the table.

Can follow the below approach.

2.How to send the selected data to other form.


Just my thoughts!!
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Typically this should involve the following steps.

  • 1. In your Java code, you fetch the data from table using JDBC. I hope you are good at it.
    2. Bind the fetched values (typically in a JavaBean which is used as a POJO (Plain Old Java Object)) to any of the request or session scopes depends on your need. Request scope is for a lesser life span as the values will stay only for this request's lifecycle. Session scope is bigger as the values continue stay for the entire session.
    3. Redirect the control from your Java code (typically a Servlet which will act as a controller) to the required JSP page
    4. Using EL (Expression Language) and custom Tag (C tags) you can retrieve the bound value with the key and iterate the value to display them in a table.


  • Next thing comes how to select the value and send it to other form.

    Here it just separates from your previous flow. After displaying the values in the JSP pages, you think it is a fresh request.

    Along with each row you add a control (say a check box or a radio button depends on your need). The user has to click on the control (say a radio button of his choice). While you are displaying the table with a radio button, you have to map or bind the radio button with the unique id (say database table's primary key for example) for each radio button.

    On clicking that radio button and a submit button the request will have to submitted to a different JSP page. The selected radio button will have the primary key as its value, which you can retrieve in the forwarded JSP page using the Expression Language as follows.



    with the radioButton Id you can get the data here in this JSP page. But how will you get the full details of the row with the passed Id?

    There are two choices.

  • 1. You can retrieve the complete values from DB with the radioButton Id as a primary key
    2. You can store the values in a HashMap in your application (they call it as a cache) by having the primary key as a Key and the appropriate POJO (Java Bean) as a value into the hashmap. Whenever you want the full details, pass on the radioButtonId (as a key) to hashmap and retrieve the POJO. Then you will get the full details in the POJO.


  • Hope this helps!!


    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: crating a table using JSP