4. Creating Struts Application
Create web Project and select struts as framework.
Action Servlet
Name
Action URL
Pattern
5. Login.jsp
Create Login jsp page.
Add following taglibs i.e. html
<%@ taglib uri="http://struts.apache.org/tags-html"
prefix="html" %>
Add form using html
<html:form action="/login">
<html:submit value="Login" />
</html:form>
Add table using palette and two text fields using html
tag.
6. success.jsp
Add bean tag at top of page by using strut bean
taglib.
Now add following:
7. ActionForm Bean
This bean used to persist data between requests.
When user submits data, it is stored temporarily in
form bean. To be redisplayed in form page in case of
format problem or in success page.
To add actionForm bean, create new actionForm
bean from strut category and give name
LoginForm.java.
Add email variable in LoginForm.java bean and add
setter and getter functions.
After that you can see changes appear in struts-
config.xml file.
8. Action Class
When form is received, function of action object is
executed and data is processed. It also decides which
view to forward processed data.
Create Action Class from wizard from struts category
by giving name LoginAction with following:
Same Path given
in form of login
page
9. Associate action class with form bean (LoginForm.java) previously created.
Delete forward slash from input resource.
Set scope to Request.
Deselect the Validate ActionForm Bean option
10. Validate Form
Your LoginAction file will look like this:
It redirects the request for success view.
But is desirable to validate input before forwarding it to appropriate view.
12. Adding forward Entries to struts-
config.xml
In order for the application to match JSP pages with forwarding conditions
returned by LoginAction's execute method, you need to add forward entries to
the struts-config.xml file.
Open struts-config.xml amd right click anywhere in file.
select struts and add forward and add following:
13. Setting welcome page in web.xml
Goto Page tab og web.xml file and change the
welcome file to login.jsp
That’s it