I built a Java web application with multiple servlets and jsps. I first had servlets only for shopping cart options such as adding products and deleting products etc. But then noticing lot of Java code in jsps I made a servlet for every Dynamic jsp which solved part of my problem. I want to know whether my design is good or bad. Or is their other way to reduce Java code from the jsp?
Share
You could consider a MVC framework such as Spring MVC. This will allow you to consolidate your java code in Controller classes and use JSP’s for what they are generally good for which is serving as a template engine. Plus with Spring you will only need to configure a single servlet for the dispatcher servlet.
Leveraging an MVC has additional benefits because you are working with a well known abstraction. A lot of boiler plate has been written for you. You can map your model data to simple POJOs that can be rendered cleanly in the JSPs through the Spring Tag Library. The Spring Bean Container will provide boiler plate Dependency Injection code that will allow you to write more modular,testable code faster.
The net out is working with raw JSPs and Servlets is a thing of the past. A ton of convenience code has been built on top of the spec and its implementations. Any implementation that you do will end up repeating a lot of this work(without the benefit of thousands of users testing it for you).