About Struts 2.2.1 Login application
Posted on: December 2, 2010 at 12:00 AM
In this tutorial you will learn about the struts struts2.2.1 login application

About Struts2.2.1 login application

In the most common login application there is  login form which is takes user's id and password in this form and clicks on submit button. Then this id and password goes to the Action. The Action checks the validity of the id and password. If both is valid then it return SUCCESS otherwise it add the error message to the returns ERROR.

All the Actions used in application must be mapped into the struts.xml. It processes the every request coming from the client / browser.

To create an login application At first create a login page in JSP(Java Server Pages). All the JSP files written for struts uses the struts specific tags. To use these tags you need to include them in directive as

<%@ taglib prefix="s" uri="/struts-tags" %>

here struts-tags is the name of the tag present in the current directory.

In the form action the name of the action is given. All the input/output field used in the JSP file must be defined in a bean. Because these fields takes the value from that bean. All the elements used in a special way. Such as prefix is fixed the colon and then type of the field is placed.

example-     <s:textfield name="userName" label="Login Name">   

<s:form action="doLogin" method="post">

Next you need to write the action. The action checks the forms and then forwarded the control to the appropriate page. There are many classes and interfaces present. You need to extend or implement them and override there execute() methods. return SUCCESS, LOGIN, ERROR etc. And if user name and password is correct there respective session is created. And this session is maintained until the user logoff.

And then you need to map the struts.xml file. This file maps the action class to there name space. for example -

<action name="doLogin" class="net.roseindia.LoginAction">
    <result name="input">/jsp/login.jsp</result>
    <result name="error">/jsp/login.jsp</result>
    <result>/jsp/loginsuccess.jsp</result>
</action>

Here class file is LoginAction.java it is mapped with its full package is name, and given a name doLogin.

Note- Every file must be mapped in the struts.xml file must be mapped with their root directory. Every class file must be mapped with there fully qualified package name.

Related Tags for About Struts 2.2.1 Login application:

Advertisements

Ads

 
Advertisement null

Ads