This tutorial shows you what is servlet and jsp with its difference and how it works with web application
When Web began to be used for delivering services, Common Gateway Interface (CGI) server-side scripts were the main technology used to generate dynamic content.
Since CGI scripting technology had many shortcomings like platform dependence and lack of scalability.
To overcome these limitations, Java Servlet technology was created as a portable way to provide dynamic, user-oriented content.
A servlet is a Java programming language used to create request-response programming model. Although servlets can respond to any type of request, they are commonly used to HTTP-specific request.
Servlet Technology uses two main packages to handle HTTP request response
These packages provide interfaces and classes for writing servlet programming to handle GET and POST http request.
You can download the jar from http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
what is servlet
Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.
What is JSP
JavaServer Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>.
Difference between jsp and servlet
- Servlet is html in java whereas JSP is java in html.
- JSP can be compiled into Java Servlets
- JSP is a webpage scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content
- In MVC, jsp acts as a view and servlet acts as a controller.
which is better jsp or servlet
JSP is preferred When you have more stuff to do with design part.
Servlet is preferred for creating communication between design and Business layer.