GeeCON Prague 2014*
The moose likes Struts and the fly likes How to store HTML table values in DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to store HTML table values in DB" Watch "How to store HTML table values in DB" New topic
Author

How to store HTML table values in DB

Raveesh Lawrance
Greenhorn

Joined: Mar 13, 2009
Posts: 7
I am new to struts. i am having one jsp file that contains datas with table. i want to collect all the table data values and stroe it in DB while clicking the submit button. how to do that... please help me.... Thanks in advance....
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

This is a basic things which could be done, if you have some experience in JSP/Servlets[This is prerequisite for Struts]

Ok, still this will be a good start !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Raveesh Lawrance
Greenhorn

Joined: Mar 13, 2009
Posts: 7
ok Thanks. Please help me how to store table values in DB
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Raveesh Lawrance wrote:ok Thanks. Please help me how to store table values in DB

I provided a link in my first reply to your first thread, Still I'm giving some more,
http://wiki.apache.org/struts/StrutsArticles
You have to learn this basics first, then If you were stuck between implementing, then you post here about where you stuck, What you did and what you expect ??
Raveesh Lawrance
Greenhorn

Joined: Mar 13, 2009
Posts: 7
jsp file - That contains table with 3 Row values and one submit button, while clicking the submit button all the table values should pass to java class file using server.






Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Raveesh Lawrance wrote:jsp file - That contains table with 3 Row values and one submit button, while clicking the submit button all the table values should pass to java class file using server.

Ok, here is what you required,

1. ActionForm(bean, with getter/setter property) : This holds you FORM/Table values
2. ActionClass (servlet): Called upon when you click "Submit", Process your requests
3. JSP page, (View), <table></table>
4. A java class with DB connection object and method which inserts data into DB

Can you get this ??
Raveesh Lawrance
Greenhorn

Joined: Mar 13, 2009
Posts: 7
no. i just created all the files(Action, Class, Form and DB) I need the procedure how to pass the all table values into javaclass file while clicking submit button.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ok,
struts-config.xml

JSP


Action, MyAction.java

HTH
Raveesh Lawrance
Greenhorn

Joined: Mar 13, 2009
Posts: 7
Sorry i think you are misunderstood wht im trying to say.
Here is my coding.
<table>
<tr align="center">
<td align="center" style="width:300px;"> Flag Name_1 </td>
<td align="center" style="width:300px;"> 1 </td>
<td align="center" style="width:300px;"> Flag Notes_1 </td>

</tr>

<tr align="center">
<td align="center" style="width:300px;"> Flag Name_2 </td>
<td align="center" style="width:300px;"> 2 </td>
<td align="center" style="width:300px;"> Flag Notes_2 </td>

</tr>
</table>
<input style="background-color:010280; color:white" type="Submit" name="commit" value="Commit">

I want to pass all these table datas into java class while clicking the commit button

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Use Code Tags

A point to remember, you must declare 'bean', like

And its mapping in correct action tag
Dhruva Mistry
Ranch Hand

Joined: Nov 21, 2008
Posts: 67

Raveesh Lawrance wrote:Sorry i think you are misunderstood wht im trying to say.
Here is my coding.
<table>
<tr align="center">
<td align="center" style="width:300px;"> Flag Name_1 </td>
<td align="center" style="width:300px;"> 1 </td>
<td align="center" style="width:300px;"> Flag Notes_1 </td>

</tr>

<tr align="center">
<td align="center" style="width:300px;"> Flag Name_2 </td>
<td align="center" style="width:300px;"> 2 </td>
<td align="center" style="width:300px;"> Flag Notes_2 </td>

</tr>
</table>
<input style="background-color:010280; color:white" type="Submit" name="commit" value="Commit">

I want to pass all these table datas into java class while clicking the commit button




you can put javascript for onSubmit event besides the <form> just call a method to take the value of needed fields and
in java class you can set the values


Dhruva
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

dhruva mistry wrote:
you can put javascript for onSubmit event besides the <form> just call a method to take the value of needed fields and
in java class you can set the values


How?
Dhruva Mistry
Ranch Hand

Joined: Nov 21, 2008
Posts: 67

Sagar Rohankar wrote:
dhruva mistry wrote:
you can put javascript for onSubmit event besides the &amp;lt;form&amp;gt; just call a method to take the value of needed fields and
in java class you can set the values


How?



likewise:



with the class:
class MyBean extends ActionForm
{
String flagNameOne;
String flagNameValue;
.
.
// other properties

// getter/setter here
}


Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

dhruva mistry wrote:



Have you read from start, what are we trying to do here, simple GET and INSERT data..
 
GeeCON Prague 2014
 
subject: How to store HTML table values in DB