Discussions

Web tier: servlets, JSP, Web frameworks: Servlet and JSP

  1. Servlet and JSP (11 messages)

    When would i use Servlet and When would i use JSP?
    Thankx in advance for any reply.

    Abdulla

    Threaded Messages (11)

  2. Servlet and JSP[ Go to top ]

    well it actually depends on WHAT and HOW do u want to implement ur application.

    u can use only JSP to write ur entire application.
    at the same time u can only use servlet to write ur application.

    JSP are easier to code and far more readable cause they allow u to embed both static HTML content which form the look and feel of ur page and also the JAVA code which is responsible to send out dynamic content on to the browser (for eg querying the database, fetching the records and then rendering them as HTML)

    u can achieve above task using servlet also but then to render static HTML page u again have to use JAVA code - typically - response.getWriter().println("HTML")
    this makes the code a bit more untidy.

    apart from the pure JSP and pure SERVLET approach u can also use the Servlet-JSP combination approach, which i think is the best. its is also called Servlet-template based approach. it allows u to seggregate the presentation layer (HTML content) from the presentation logic (java code).
    the presentation layer is contained in a JSP and presentation logic is contained in a servlet. in fact i am in the process of writing a framework to achieve the same. it employs both servlet and jsp. it also uses a very powerful feature of JSP - custom tag libraries effectively.

    lemme know if i answered ur query and if u need more info

  3. Servlet and JSP[ Go to top ]

    Hi,
     The application gonna to be M-Commerce(Mobile Commerce) along with EJB stuff & we'have planned to implement this in Web Logic Server.

    Abdulla
  4. Servlet and JSP[ Go to top ]

    well it actually depends on WHAT and HOW do u want to implement ur application.

    u can use only JSP to write ur entire application.
    at the same time u can only use servlet to write ur application.

    JSP are easier to code and far more readable cause they allow u to embed both static HTML content which form the look and feel of ur page and also the JAVA code which is responsible to send out dynamic content on to the browser (for eg querying the database, fetching the records and then rendering them as HTML)

    u can achieve above task using servlet also but then to render static HTML page u again have to use JAVA code - typically - response.getWriter().println("HTML")
    this makes the code a bit more untidy.

    apart from the pure JSP and pure SERVLET approach u can also use the Servlet-JSP combination approach, which i think is the best. its is also called Servlet-template based approach. it allows u to seggregate the presentation layer (HTML content) from the presentation logic (java code).
    the presentation layer is contained in a JSP and presentation logic is contained in a servlet. in fact i am in the process of writing a framework to achieve the same. it employs both servlet and jsp. it also uses a very powerful feature of JSP - custom tag libraries effectively.

    lemme know if i answered ur query and if u need more info

  5. Servlet and JSP[ Go to top ]

    Excellent reply, Kapil.

    The next question will be when to use JSP, Servlet, Session beans and entity beans.

    The book Mastering EJB has some excellent material on that.

    ;-)
    Rahul.
  6. Servlet and JSP[ Go to top ]

    I agree with you guys. That seems most reasonable. However, when I went thru j2ee blueprints, I got a different impression. It seems j2ee enterprise team prefers jsp over servlet in most occasions. Look at the petsore sample application. Main.jsp contains only java code; there is no html tag; it's purely java program logic but still they put it in a jsp !! I donot understand.

    Is there anybody who understands this ? There must be something else.

    Also there are some other issues I donot appreciate when I go thru petstore sample application code ? Any takers?

    thanks...sanjib



  7. Servlet and JSP[ Go to top ]

    hey sanjib please lemme know from where i can download this petstore app. i will have a look.
  8. Servlet and JSP[ Go to top ]

    kapil,
    go to http://java.sun.com/j2ee/download.html to download the sample petstore application.
    thanks...sanjib
  9. Servlet and JSP[ Go to top ]

    Sanjib:

    I agree with you.
    I got the exact same impression that you got when i went through the Pet Store application.

    CJ
  10. Servlet and JSP[ Go to top ]

    jsp can be used when you want to work out some request and response in the html itself rather sending the process to server and slow down the performance.
    where as servlets can be used in server side and responded in html/text from where it is calle,this will slightly slowdown the processing.

      
  11. Servlet and JSP[ Go to top ]

    jsp can be used when you want to work out some request and response in the html itself rather sending the process to server and slow down the performance.
    where as servlets can be used in server side and responded in html/text from where it is calle,this will slightly slowdown the processing.

      
  12. Re: Servlet and JSP[ Go to top ]

    Why the serlvet single thread model interface is depricated? And how to provide synchronization in servlets?