Using Struts 1 tags in JSP with Java Bean Step 14
Now we are going to test out our our tags and attach a form to our Java Bean.
You need to replace your UserForm.java with this code:
Add this method to UserAction.java
In your action form you added getter and setter methods to retrieve and set the users names and their email addresses. These are the same column names you have in the database.
You will have the user input data on the webpage, and when they submit the form, your action method will be called. The UserForm will pull the data to make sure the data was set correctly.
Now that we know your tiles work correctly, you can remove the test comments in your header.jsp, classiclayout.jsp and footer.jsp pages.
You need to add the rest of these tags to your include-taglibs.jspf page.
These tags will allow you to use other tags that you will need in your jsp page.
Copy this code to your user.jsp page
At the top of the page you should include your import. Every page should include this import tag. You then have the struts html:form that informs what Struts Action will be called and what method will be called when the user submits the form. When the user submits this form, the UserAction.do will be called and it will call the setUser method that we added to the UserAction class. You will notice that you have the html:text tag in use too. The html:text tag attaches it to the UserForm class. The property is what method it is accessing. The first name is attached to the firstName method. The actual method is called FirstName, but you always start the property in lowercase, not uppercase. The rest of the page is regular html with a submit button at the bottom so the user can submit the form.
Build your new project and go to your localhost to see if your tags work correctly.
When you visit the project, you should see some input fields. Input some data, press submit, and verify that the data you inputted prints in your console. If it did, then your form works correctly. In my next post I will show you how to obtain a database connection to your mySQL database you created in my prior posts.
Go To Step 15

2 comments:
well i am new to struts i am using tile with struts 1.3 the tiles is working fine..
but when i click on submit button control the next page displays but it is not in tiles.
Can u provide a sample example of
using tiles with "subimt" and still the success or the failure page displayed in the same tile.
how to do that with validations....
Lot of thanks in advance
I can't post any examples at the moment since I am currently traveling. But, your issue might be because you aren't pointing your struts.xml file to the tiles file.
You should verify the following:
1) Check your action forward from your action class to make sure it points to the struts.xml forward. That struts.xml forward should point to your tiles file and your tiles file will point to the correct JSP page. You can see my examples on my blog. I have a struts.xml and tiles.xml files posted on my blog.
Post a Comment