Duration: 16 minutes
Summary: In this tutorial, we will create the main Finance Application Structure, and review all steps used before to create our first App. Inside this, we will design the first transaction (Credit) and test it deploying the struts application to Tomcat. In this course, we’re going to learn the Java Struts 2 Technology, presenting a Tomcat Web solution and exploring how a Finance Management Software can be designed using these resources.
Technology Used: Java, Apache Struts 2, Eclipse, Tomcat
Keyword: Java, Eclipse, Struts 2, Tomcat, apache, mvc
Hi everybody. Welcome. Let's continue our struts course. Right now we are
going to create a new application. We made a previous application testing
concepts. At this time, we're going to create a new application. We will
design and develop our financial application using Struts.
In your workplace at Eclipse, you can create a new project, using the new
menu. Here you choose Java, and Tomcat Project, as we did before. At the
project name, you type FinancialApp, for application. OK. The context name
will be FinancialApp. You can delete the other project. Right now you have
a brand new application to use those steps that we used before. Let's do
that. First of all, let's create the struts xml file, as we made before.
Now, you have to set this doc type declaration.
That will help you to complete the rest of the document, using the
IntelliSense resource. When you type, you have the struts text, and all
the older options to help you. We're going to create a new package here.
The new package we're going to call default. We're going to use the
accents, struts default. We will set the name space as a slash, so you have
the package declaration. Right now we can think about the transactions that
we are going to design, using the struts, as we create this declaration
package. Now we can set the actions to our package. The actions are
everything that we are going to make it a customized procession, obviously,
using some rules. We are going to design three basic transactions. The
first is credit. The second is debit. The third is statements.
Let's create the first section using the name, credit. You have to set a
Java class to make the procession and maintain all the rules that you will
use. We are going to call this something like Mr.Bool.creditaction. We're
going to call this class credit action. The next step is to create a new
package. I'm going to call this package Mr.Bool. Inside there the Mr.Bool
package, I'm going to create a new Java class to respond to me as a credit
action. All right.
Once it's created, this class will be used from struts to execute our
action logic, our business rules. Before creating any rules for this credit
action, we're going to create and set a new .jsb file to respond as our
action. We're going to create credit.jsb. Right now let's type credit.
Inside the body, we're going to create the form. The form will print on the
screen, all the web components, to help us execute this action. As we made
before, we have to insert the taglib tag, like this. We will create a brand
new form using some tags. It's something like this. On form, we find the
text field. Name an amount to set the amount of your credit action. Then
hit the submit button, with the label OK, calling the method name execute.
It's something similar to what we made before. You have this .jsb file configuration.
Now, let's give some attention to the other side of the application. You
have the credit action. Inside the credit action you have to create a
method name, execute, something similar as we made before. It's just like
you have here on your .jsb file. You have to create a public returning
a String. Call it execute. Inside here, we're going to set a
bunch of comments to make things happen. By this time, we have to know that
we must have inside our class, private attributes with the same name as we
have inside the .jsb file.
Once you have a private attribute, you can create a getter and setter Fields.
Your Eclipse will create this automatically. We have here the
main step for the credit action. The struts.xml file will work, as a map to
our application. We must have inside the action tag, some results. You can
set a name to these results. First, you will type successresults, and later
you will set and narrower results. After this, inside the results tag you
will add the page that you want it to direct to once your credit action is
done successfully. Let's set our results tag. Name it success. Direct to
credit.jsp. Let's create a new document. Call it error.jsp, to set once you
have an error. Here you have a navigation map to your action. This is very
After this, we have to create logic. We have to create a business code for
this action, inside the method, execute. You will have a design code. If
you have your logic processed, and your credit made, you will have a
successful method. Beside this, you can have any kind of error happening
inside your tool. Then you will have a different navigation result.
I will return at this moment to success, just to test if we are having a
good process action. As we made before, I'm going to add inside the web, a
directory web.xml file. Set the credits to .jsb. All the other attributes,
I just copied from another application. It's the same. You have the
credits.jsb file to execute method. Inside the submit tag, call the action.
Name it credit. You have the struts.xml, expecting for some result inside
the process of credit action. This result will be a success or error. Let's
create the work directory on Tomcat. Right now we're going to test the
application. I almost forgot. Once you have all your libraries here inside
your web base folder, you can test the application. We're going to call the
browser. Let's call financial application. You have the field right here
inside to insert a value. I'm going to submit ten and submit.
You have the action running. It's very easy. If you have any kind of
trouble, you have to go to your locked files in your Tomcat to see what's
happening. Inside the logs folder, you have the file name, with the present
date. In here you can look for all information, even from your application.
I see that everything is running OK for now. Thank you for very much. See
you next class.