Dispatching Requests to an Action Class
The second requirement for using a Controller servlet is that the servlet must be able to distinguish requests for different types of actions. The Struts servlet uses a configuration file with mappings from a part of the request path to the corresponding action class to handle this. The file is named struts-config.xml and is located in the WEB-INF directory for the application by default. Example 19-8 shows the configuration file used for the Project Billboard application.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<global-forwards>
<forward name="login" path="/ch19/login.jsp" redirect="true" />
<forward name="main" path="/ch19/protected/main.jsp"
redirect="true" />
</global-forwards>
<action-mappings>
<action path="/ch19/authenticate"
type="com.ora.jsp.servlets.AuthenticateAction" />
<action path="/ch19/logout"
type="com.ora.jsp.servlets.LogoutAction" />
<action path="/ch19/protected/storeMsg"
type="com.ora.jsp.servlets.StoreMsgAction" />
<action path="/ch19/protected/updateProfile"
type="com.ora.jsp.servlets.UpdateProfileAction" />
</action-mappings>
</struts-config>It’s an XML file, as are most configuration files nowadays. The first part of the file defines what Struts calls global forward mappings. I’ll get back to them ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access