Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Login web page - Course Java Struts: Developing a Finance Management Software – Part 4 | Java courses

In this tutorial, a login web page is created to show an action must be configured to work properly.

Course:  

Duration: 13 minutes

Summary: In this tutorial, we will create a login page and learn how to configure it to work properly. We’ll show and configurate all struts tags needed to this example. Again, the struts.xml configuration file is showed and configured to provide to the example the navigation structure needed. 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

Transcript: Hello everybody, please be welcome. Let's continue our tutorial using Java struts. Right now, we're going to create a new action to use another struts text.

We're going to make a log-in screen to our system. Also, let's create a jsp file to serve as a log-in page. Right now, we're going to create a new jsp file. We're going to call this as login.jsp, jsp file html. The first thing that you need to do is to insert the taglib prefix inside your jsp document. This will alone provide your access to all taglib components, all struts components to your jsp document. Inside the strut page, let's type login.

On the title, inside the body tags, let's create the form. Form text. Just like a regular form tag, a regular form tag from html or another web language. We must have an action here. This action is the right action. On the struts.xml, I will call it, login. Here, we have to insert the fields that must be included on this document.

First, we will have the text field, to login. You must insert a name, let's use username. You can insert a label and a size. After this, we will use the password tag; that must have a name. You can insert a label and a size. Both of these, but appearing below the form, we will include the submit button, that must call a method. This method is the main method called inside the model class. In this index section we had a method called execute. In that case, we called it as a default method. Here, you can call any other name it method. We use this name, execute, as our method. You can also set a label here.

The next step is to create an action. Name it; Login, let's use the lower case here. We have to set a class that will be called when this action is set. We must have a result, and the result is named, SUCCESS. You can call it an index.jsp or you can call it a main page .jsp.

Next step, let's create this mainpage.jsp. Just to see how this works in another action. Same taglib here, declaration. We will make the called print on screen our login user name. Value=username. When it's done, let's create the LoginAction. A new class, inside WEB-INF/src folder. The LoginAction must have a private property. Typed String, name it username equal as you have on your jsp file, and another String, name it password.

Write this, create the gathering setter for user name and password. Then you have to create the public string. Name it, execute. This method must return. SUCCESS, if the execution is OK.

Here inside this method, you can create your logic to verify the user name and password. We will just create an, if, to compare the user name and password as fixed values. So, if(this.username.equals("admin"), && this. password.equals. let's put, ("admin")), the password. The code will { return "SUCCESS"} else{return "ERROR";.

The next step, we must set the ERROR message on the struts.xml. Let's do it. You have SUCCESS as return, and then you must have an ERROR return result. So here let's create an ERROR .jsp document. Just inform the user that something wrong has happened.

Let's make a review on the struts.xml to better understand how the action will work. First of all the application will begin right now. Not more on the index page and we will set this on the web.xml file here, on the welcome file tag. After this, the application will call the Login .jsp, let me find here. You will see a form here on screen. You will type the user name and password, and the action, we will call the LoginAction, as we defined on struts.xml. This action.

The LoginAction will call the class called Mr.Bull.LoginAction, here. As we defined it on the form, inside the login. jsp web page. The submit, will call a method, call it, execute. This method execute, inside the LoginAction, defined by this action declaration will set the logic to LoginAction inside the method execute, right here.

The code will make a test. If username equals admin, and password equals admin, then the code will return SUCCESS, else, return ERROR. Inside the struts.xml action log in, ou have both results, SUCCESS and ERROR defined. Each one will send and the redirect the execution to which page, main.jsp or error.djsp.

Let's test the code. Open the web browser, on the local host struts test, 01. The main page, the welcome page will be the Login.jsp. So let's type admin and let's type anything else but the right password here, like 1,2,3. We receive this message, an error. Coming back and typing in the right password, click submit. You will find that mainpage. jsp., hello and your property admin. Now we can go ahead and create our real application using struts. That's all for now, thank you very much. See you later.



Is a Systems’ Analyst with more than 10 years of experience. He is consultor in Porto Alegre /RS, where he works with C#, Java, among others languages, in platforms of Windows and Linux. He uses .NET framework since the first Beta...

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 2,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 1,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,33
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login