• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing Databases with Struts

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to Struts. I am learning Struts by looking at the sample example. And so far i am able to understand clearly. But as there is no database example in them i am not able to use database. I am using Struts1.

Can anyone please send some consolidated database applications or if someone can teach me it would be fantastic.

Thanks
Gaurav
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's nothing special about accessing a database with Struts, unless you're using the deprecated <datasource> configuration element--which I wouldn't recommend.
 
Gaurav Kshatriya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David

Thanks for the immediate response. But i want to say that i dont know anything about how to access a database from struts 1. So i was asking for some code examples by which i can easily understand. If you can share it would be great help.

Thanks
Gaurav
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again: search for any JDBC tutorial (if that's how you're doing it--you don't say if you're using Spring, Hibernate, etc.)

There's nothing Struts-specific about this.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Note: Each and every step before doing read the important notes and follow . I give important notes in bottom.

1. Open a NetBeans editor.

2. Select the following method for create empty project.

File -> NewProject -> Web -> WebApplication
Next -> Give project name -> select project location
Next -> Select struts (check box).
Finish.

3. Designing form inside the index.jsp

Whatever you need (textbox,button,label etc…)

4. Create a new package under source package

Right click SourcePackage -> Java Package -> Give the package name.

5. Create a new formbean file

RightClick JavaPackage -> new -> StrutActionFormBean
Give the class name

6. Create a new action file

RightClick JavaPackage -> new -> StrutAction
Give the classname , Actionpath ** (classname must be equal ActionPath)
Select Request or Session .

7. Create a new java class for DBConnect

Database connection establishment coding here.

8. Java Script

Create a new Folder for javascript under Webpages.
Rightclick javascriptfolder -> new -> File/Folder
Next -> Other folder -> EmptyFile
Next -> Give name. -> Finish.


Important Notes:

3.1 Form Creation

Give the form action Name
Create a textbox, password field, button .
Note the FormName and Property




5.1 Form bean creation

The formbean name must be equal to form name.

Egs. Formbean name is TestForm.

Then the following coding inside the FormBean(TestForm)
Declare the following variables
Variables names and property names are must be equal.



Select all the above variables and right click
Refractor -> Encapsulate Fields.
Select get and set username, password, submit -> Next -> Do Refractoring.

6.1 Strut Action creation

The strut action name and form action name must be equal.

Egs: Action name is TestAction.

Here only we will do the orginal coding .Get the form value , database manipulation etc…



Finally after complete the each and every file look up to the (strutconfig.xml) file.


Error will be occur the following situation:

1. Form name and Struts action form bean name are not match.

2. Form Action name and strut action name are not match.

3. Variable names and property names are not equal.

4. All package are properly not imported.(java and strut packages).

5. All taglib file are properly import into the designing file(*.jsp file)

6. Not proper entry for inside the strutconfig.xml file.

7. Iterate id name is equal to package Name. And In Iterate procedure bean write name is also equal to package name.


Remainig you will refer JDBC tutorial and struts tutorial.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Eswara: What's the point of the big long example if it doesn't answer the only question that was asked?!?!?! And it's "Refactor", not "Refractor".
 
Gaurav Kshatriya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Eswara : Thank you for the example. I am trying to do it.

@David : I was looking for an example like this only where i can find where the JDBC code should be written. Like Eswara has told that in ActionForm it should be written.

So its still not completly clear in my mind but i am trying. If anyone has more inputs on the same then please share.

Thanks
Gaurav
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this thread on JavaRanch, specifically this link from the FAQ regarding pre-populating ActionForms.
 
Gaurav Kshatriya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@David : Thank you for the links.

Regards
Gaurav
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic