In the previous section, the software required to develop a Struts web application was configured. In this section a very basic web project is created to ensure that everything is present and correct.
Create A Web Project
A new Dynamic Web Project is created, called StrutsProject:
The struts project properties is opened up.
The user library, created earlier, is added to the StrutsProject, and also setup to be part of the deployment:
The Struts.1.3 library is earmarked as being exported to dependent projects:
The Struts1.3 library is added as a Web Library dependency:
A Struts project is typically composed of:
- web.xml, the JEE way of defining a web application.
- struts-config.xml, the file that contains the relevant entries for the struts web application.
- jsp pages to generate the web pages (view).
- java classes to provide the functionality (model and controller classes).
- jar library files, for example data access layer components.
- property files, for the text that is displayed.
- type library descriptor files (Tld's), these files hold the syntax for custom jsp tag libraries.
A starter web.xml is shown below. This file was originally generated by Eclipse in the WebContent/WEB-INF folder. It is configured to load the Struts servlet:
<?xml version="1.0" encoding="UTF-8"?>
The struts action servlet is where all the page requests should go. It is told where to look for the struts-config.xml file, and the debug is set to level 3.
In the mapping, we inform the web container that any page request of the form *.do should be sent to the struts action servlet.
Finally, the default file is called index.jsp.
A starter struts-config.xml is created in the WebContent/WEB-INF folder:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
A new JSP is created, called index.jsp in the WebContent folder:
The contents of the file are as follows:
This is index.jsp
First Test Run
In the project tree, the project is right clicked, and debug on server is selected. A dialog pops up:
The checkbox ("Always use this server when running this project") is clicked and finish is clicked.
The project runs and Eclipse navigates to the welcome page index.jsp:
Running the project at this point is a good idea: it confirms that everything is configured correctly to run a Struts web application.
In the next section, a dynamic web page is developed using Struts.