@ApplicationScoped public class ShoppingCartService { @Inject private ProductService productService; public void addToCart(String productId, int quantity) { Product product = productService.getProduct(productId); } } public class ProductService { public Product getProduct(String productId) { } } public class ShoppingCartServlet extends HttpServlet { @Inject private ShoppingCartService shoppingCartService; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String productId = request.getParameter("productId"); int quantity = Integer.parseInt(request.getParameter("quantity")); shoppingCartService.addToCart(productId, quantity); } } <listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener>


上一篇:
下一篇:
切换中文