Results 1 to 5 of 5
  1. #1
    Buli is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default Servlets or JSP?

    Hello,

    I'm creating a small web application using Servlets and I wonder is it necessary to use JSP pages. I've read a little about it and I think I can use it, but it's easier for me to use Servlets and PrintWriter - I have some experience with it. Is something wrong in using only Servlets without JSP? Should I connect these two technologies together somehow?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: Servlets or JSP?

    It gets pretty messy using PrintWriter for outputting your HTML.
    JSPs are a lot neater for that, which is why they were created.

    Just don't mix code into the JSP...but then you are learning in the correct (IMO) order, so hopefully you won't.
    Do all the work of getting any data together that needs to be displayed by the JSP, then simply forward there and use the JSTL tags (or whatever other framework you may be using) to display that data.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: Servlets or JSP?

    JSP in fact internally uses Servlet code, it dynamically generates Servlet classes having the code that you've written in JSP. JSP is much easier to learn and even you need not restart Tomcat, when you do work with JSP files (modify the code in them).

    But JSP is quite slow when compared to that of Servlets, as said earlier, JSP container has to generate servlet classes which takes time, i can say better use Servlets if it is small. They have got really good features.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: Servlets or JSP?

    Again with the guesswork.

    Servlets are for doing the processing and calling the business logic.
    JSPs are for displaying the results.
    That's all there is to it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    wright536 is offline Member
    Join Date
    Dec 2012
    Location
    china
    Posts
    2
    Rep Power
    0

    Default Re: Servlets or JSP?

    You can use the Servlet to do things that the Jsp does.I don't know whether you understand the MVC model.
    v---view(jsp,html) ,c---controller(Servlet) ,m--model(dao,hibernate...).In a word,the Jsp can better display the data.

Similar Threads

  1. Servlets class not teaching servlets
    By tsky in forum Java Servlet
    Replies: 5
    Last Post: 04-26-2011, 10:47 PM
  2. mvc using servlets and jsp
    By dush_gos in forum Java Servlet
    Replies: 6
    Last Post: 07-09-2010, 11:32 PM
  3. servlets
    By priyacvr in forum Java Servlet
    Replies: 2
    Last Post: 09-28-2009, 07:43 AM
  4. Servlets
    By javahelp00 in forum New To Java
    Replies: 1
    Last Post: 02-28-2009, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •