Discussions

Web tier: servlets, JSP, Web frameworks: servlet and JSP combination and design issue

  1. servlet and JSP combination and design issue (3 messages)

    My task is to generate the list box dynamically based on the input XML file.

    I create a JSP page and a servlet.
    http://www.myserver.com/page1.jsp

    In page1.jsp, I have the following to call servlet from JSP page
    <jsp:include page="myproj.TableGeneration"/>

    In my case, I think I don't need servlet at all, but just Java Bean
    class to generate the table. And JSP page call that Java Bean class.

    But in what situation we need the combination of servlet and JSP?

    What do you think? Any ideas? Thanks!
  2. But in what situation we need the combination of servlet and JSP?
    Servlet and JSP are functionally equivalent. In theory, you never need to use servlets.

    In practice, Servlet and JSP are good for different things. JSP are good for operations that involve page generation (creating HTML forms) whereas Servlets are better for Java-intensive operations (processing form data).

    A common approach is to:

    1. Write JSP to create your forms
    2. Have this form target a servlet
    3. Have the servlet process the form data (for example, save it to a database).
    4. Have the servlet forward to a second JSP to display the results.

    That gives you are good distinction: JSP are for display, Servlets are for processing.
  3. I would like to add some more points to the above description which is offcoz true.

      While deciding upon Jsp with Servlets combination it is like just follow the MVC architecture.

    1. JSP/HTML for designing forms/reports
    2. Servlets must be used as a controller i.e. servlets are for just processing some common functionality ,may be entry point to an application which thereafter may use diff JSP pages.according to user input through JSP/Html
    decide upon the flow like which page to display next kind.
  4. Hi,
    One more thing u need to notice in MVC pattern is that we generally have one contrller servlet which decides what actions needs to be taken upon receiving the request from web client. In this case this stands for a single point for failure. I mean to say if your controller servlet fails in MVC pattern then whole application wont be available.
    I am just trying to point out some negatives also about MVC.This may not be directly related to your question.

    Thanks and regards,
    Amit
    My task is to generate the list box dynamically based on the input XML file.I create a JSP page and a servlet.http://www.myserver.com/page1.jspIn page1.jsp, I have the following to call servlet from JSP page<jsp:include page="myproj.TableGeneration"/>In my case, I think I don't need servlet at all, but just Java Beanclass to generate the table. And JSP page call that Java Bean class.But in what situation we need the combination of servlet and JSP?What do you think? Any ideas? Thanks!