Java Reference
In-Depth Information
L
ISTING
13.3
Continued
}
/**
This method is the implementation of the parents interface's
execute() method. It contains the core functionality of
a Service.
*/
public void execute(HttpServletRequest request,
HttpServletResponse response,
ServletContext context) throws Exception {
// Do Something Here
request.setAttribute(“example”, “Example Value”);
}
}
The only thing you need to notice about this class is that it does implement the Service's
execute()
method. In this implementation it simply adds an attribute to the
request
with a
key of
example
and a value of
Example Value
.
13
To see this Controller in action, you will need to compile the
Controller.java
,
Service.java
, and
ExampleService.java
files and move the resulting class files into the
<SERVER_ROOT>/djs/WEB-INF/classes
directory. After you have the Controller and its neces-
sary support files you need to create a simple JSP that acts as the view. We have not yet cov-
ered JSPs, but Listing 13.4 contains a simple JSP that outputs the request attribute
example
and
its value.
L
ISTING
13.4
ExampleView.jsp
<HTML>
<HEAD>
<TITLE>
Example View
</TITLE>
</HEAD>
<BODY>
<H1>
Example JSP View
</H1>
The value added to the request was <%= request.getAttribute(“example”) %>
</BODY>
</HTML>