dependency-injection servlet configuration
Resin allows servlets to be configured using dependency injection. With Resin, servlets can use Java Bean-style configuration. A "Java Bean"
is just a Java class that follows a simple set of rules. Each configuration
parameter
The following package test; import java.io.*; import javax.servlet.http.*; import javax.servlet.*; public class HelloServlet extends HttpServlet { private String _greeting = "Default"; public void setGreeting(String greeting) { _greeting = greeting; } public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { PrintWriter out = res.getWriter(); out.println(_greeting); out.close(); } } The servlet configuration sets the property
inside an init/servlet tag. After Resin instantiates the servlet object,
it looks at the configuration file for any <init> section. Resin then
calls a Resin will perform any type conversion necessary, so you can use
integers and doubles as well as strings. After Resin calls the When Resin initializes the servlet, it will make the following calls:
<web-app xmlns="http://caucho.com/ns/resin" xmlns:test="urn:java:test" xmlns:ee="urn:java:ee"> <test:HelloServlet> <ee:WebServlet urlPatterns="/hello"/> <test:greeting>Hello, bean-style World</test:greeting> </test:HelloServlet> </web-app>
|