Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming /Difference Between JSP and Servlets

Difference Between JSP and Servlets

December 17, 2010Posted byAndrew

JSP vs Servlets

A Servlet is a server side software component written in Java and runs in a compatible container environment known as a Servelt container (like Apache Tomcat). Servlets are predominantly used in implementing web applications that generate dynamic web pages. They can however generate any other content type like XML, text, images, sound clips, PDF, Excel files programmatically.

A Servlet written to generate some HTML may look like this:

public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

PrintWriter w = response.getWriter ();
w.write(“”);
w.write(“”);

Date d = new Date();
w.write(d.toString());
w.write(“”);
w.write(“”);
}
}

The code above contains a mixture of HTML and Java source code. Such is not very readable and maintainable. JSP which stands for JavaServer Pages provides a better alternative. For example, the following is a fragment of JSP code that results in identical output:

<%@page import=”java.util.Date”%>


<%= new Date().toString() %>

Web page authors find JSP easier to write and maintain. JSP files are however translated into Servlets by a Servlet container at the time JSP files are first accessed. However, business logic writers find Servlets to be easier to work with.

A request received by a web application should trigger the execution of some business logic and then generate a resultant web page as the response. In modern day web applications, controlling the overall request processing cycle is mostly handed by Servlets. As the last stage in processing a request, such a Servlet generally hands over the responsibility of generating the dynamic HTML to a JSP.

Related posts:

Difference Between Get and Post Difference Between Dictionary and Hashtable

Filed Under:ProgrammingTagged With:Dynamic HTML,HTML,Java,Java Server,JSP,Servlet,源代码

About the Author:Andrew

Leave a ReplyCancel reply

Your email address will not be published.Required fields are marked*

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Yellow Jacket and Bee

Difference Between Concentration and Molarity

Difference Between Concentration and Molarity

Difference Between Hydrogen and Helium

Difference Between Hydrogen and Helium

Difference Between Intersex and Transgender

Difference Between Mitral Valve and Tricuspid Valve

Difference Between Mitral Valve and Tricuspid Valve

Latest Posts

  • What is the Difference Between Vacuum Pump and Compressor
  • What is the Difference Between Soil and Clay
  • What is the Difference Between Soil Air and Atmospheric Air
  • What is the Difference Between Hotplate and Induction Cooker
  • What is the Difference Between Steroids and Antibiotics
  • What is the Difference Between Gastritis and Pancreatitis
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Useand Privacy Policy:Legal.