programing tip

JSF, Servlet 및 JSP의 차이점은 무엇입니까?

itbloger 2020. 9. 29. 07:23
반응형

JSF, Servlet 및 JSP의 차이점은 무엇입니까?


JSP와 Servlet은 서로 어떤 관련이 있습니까? JSP는 일종의 서블릿입니까? JSP와 JSF는 서로 어떤 관련이 있습니까? JSF는 ASP.NET-MVC와 같은 일종의 사전 빌드 UI 기반 JSP입니까?


JSP (JavaServer 페이지)

JSP는 서버 시스템에서 실행 되는 Java보기 기술로 , 클라이언트 측 언어 (예 : HTML, CSS, JavaScript 등)로 템플릿 텍스트를 작성할 수 있습니다. JSP는 페이지 흐름 또는 출력을 동적으로 제어 할 수있는 Java 코드 조각으로 지원되는 taglibs를 지원합니다 . 잘 알려진 taglib는 JSTL 입니다. JSP는 또한 대부분 taglibs와 결합하여 페이지, 요청, 세션 및 애플리케이션 범위에서 사용 가능한 속성을 통해 백엔드 데이터에 액세스하는 데 사용할 수있는 Expression Language를 지원합니다 .

JSP가 처음 요청되거나 웹 앱이 시작될 때 서블릿 컨테이너는이를 확장하는 클래스로 컴파일 HttpServlet하여 웹 앱의 수명 동안 사용합니다. 생성 된 소스 코드는 서버의 작업 디렉토리에서 찾을 수 있습니다. 예를 들어 Tomcat 에서는 /work디렉토리입니다. JSP 요청에서 서블릿 컨테이너는 컴파일 된 JSP 클래스를 실행하고 생성 된 출력 (일반적으로 HTML / CSS / JS)을 네트워크를 통해 웹 서버를 통해 클라이언트 측으로 보내면 웹 브라우저에 표시됩니다.

서블릿

Servlet은 서버 시스템에서 실행 되는 Java API (응용 프로그래밍 인터페이스) 로 클라이언트의 요청을 가로 채 응답을 생성 / 전송합니다. 잘 알려진 예는 인 HttpServlet방법을 제공하는가에 후크 HTTP 것은 대중적인 사용 요청 HTTP 방법을 같은 GETPOST. 에서 구성 할 수 HttpServlet있는 특정 HTTP URL 패턴을 수신 하도록 구성 할 수 있습니다.이 패턴 은에서 구성 할 수 있습니다 web.xml. 또는 최근에는 주석 과 함께 Java EE 6 에서 구성 할 수 있습니다 @WebServlet.

서블릿이 처음 요청되거나 웹 앱 시작 중에 서블릿 컨테이너가 인스턴스를 생성하고 웹 앱의 수명 동안 메모리에 보관합니다. URL이 서블릿의 URL 패턴과 일치하는 모든 수신 요청에 대해 동일한 인스턴스가 재사용됩니다. 으로 요청 데이터에 액세스 HttpServletRequest하고으로 응답을 처리 할 수 있습니다 HttpServletResponse. 두 객체의 오버라이드 (override) 방법 중 내부 메소드 인자로 사용할 수 있습니다 HttpServlet같은, doGet()그리고 doPost().

JSF (JavaServer Faces)

JSF는 Servlet API 위에 구축 된 컴포넌트 기반 MVC 프레임 워크 이며 JSP 또는 Facelets 와 같은 다른 Java 기반보기 기술에서 사용할 수있는 taglibs를 통해 컴포넌트제공합니다 . Facelets는 JSP보다 JSF에 훨씬 더 적합합니다. , 복합 구성 요소 와 같은 훌륭한 템플릿 기능을 제공 하는 반면 JSP는 기본적으로 JSF에서 템플릿 만 제공 하므로 원시 Java 코드 (약간 불투명하고 지루한 작업이 많음)로 사용자 지정 구성 요소를 만들어야합니다. 반복되는 구성 요소 그룹을 단일 구성 요소로 바꾸려고합니다. JSF 2.0 이후로 JSP는 Facelets를 선호하는 뷰 기술로 더 이상 사용되지 않습니다.<jsp:include>

참고 : JSP 자체는 더 이상 사용되지 않으며 JSF와 JSP의 조합 만 사용되지 않습니다.

참고 : JSP는 Taglibs, 특히 ( Tag File ) 변형 을 통해 훌륭한 템플릿 기능을 제공합니다 . JSF와 결합 된 JSP 템플릿은 부족합니다.

MVC ( Model-View-Controller ) 프레임 워크 인 JSF는를 FacesServlet유일한 요청-응답 컨트롤러제공합니다 . 사용자 입력 수집, 유효성 검사 / 변환, 모델 객체에 배치, 작업 호출 및 응답 렌더링과 같은 표준적이고 지루한 HTTP 요청 / 응답 작업이 모두 필요합니다. 이렇게하면 기본적으로 View에 대한 JSP 또는 Facelets (XHTML) 페이지 Model 로 JavaBean 클래스가 생성됩니다 . JSF 구성 요소는보기를 모델과 바인딩하는 데 사용되며 (예 : ASP.NET 웹 컨트롤이 수행하는 것처럼) 모든 작업을 수행하기 위해 JSF 구성 요소 트리FacesServlet사용합니다 .

관련 질문


참조 http://www.oracle.com/technetwork/java/faq-137059.html를

JSP 기술은 Java 기술 제품군의 일부입니다. JSP 페이지는 서블릿으로 컴파일되며 서버에서 처리를 수행하기 위해 JavaBeans 구성 요소 (beans) 또는 Enterprise JavaBeans 구성 요소 (enterprise bean)를 호출 할 수 있습니다. 따라서 JSP 기술은 웹 기반 애플리케이션을위한 확장 성이 뛰어난 아키텍처의 핵심 구성 요소입니다.

참조 https://jcp.org/en/introduction/faq를

A: JavaServer Faces technology is a framework for building user interfaces for web applications. JavaServer Faces technology includes:

A set of APIs for: representing UI components and managing their state, handling events and input validation, defining page navigation, and supporting internationalization and accessibility.

A JavaServer Pages (JSP) custom tag library for expressing a JavaServer Faces interface within a JSP page.

JSP is a specialized kind of servlet.

JSF is a set of tags you can use with JSP.


From Browser/Client perspective

JSP and JSF both looks same, As Per Application Requirements goes, JSP is more suited for request - response based applications.

JSF is targetted for richer event based Web applications. I see event as much more granular than request/response.

From Server Perspective

JSP page is converted to servlet, and it has only minimal behaviour.

JSF page is converted to components tree(by specialized FacesServlet) and it follows component lifecycle defined by spec.


Servlets :

The Java Servlet API enables Java developers to write server-side code for delivering dynamic Web content. Like other proprietary Web server APIs, the Java Servlet API offered improved performance over CGI; however, it has some key additional advantages. Because servlets were coded in Java, they provides an object-oriented (OO) design approach and, more important, are able to run on any platform. Thus, the same code was portable to any host that supported Java. Servlets greatly contributed to the popularity of Java, as it became a widely used technology for server-side Web application development.

JSP :

JSP is built on top of servlets and provides a simpler, page-based solution to generating large amounts of dynamic HTML content for Web user interfaces. JavaServer Pages enables Web developers and designers to simply edit HTML pages with special tags for the dynamic, Java portions. JavaServer Pages works by having a special servlet known as a JSP container, which is installed on a Web server and handles all JSP page view requests. The JSP container translates a requested JSP into servlet code that is then compiled and immediately executed. Subsequent requests to the same page simply invoke the runtime servlet for the page. If a change is made to the JSP on the server, a request to view it triggers another translation, compilation, and restart of the runtime servlet.

JSF :

JavaServer Faces is a standard Java framework for building user interfaces for Web applications. Most important, it simplifies the development of the user interface, which is often one of the more difficult and tedious parts of Web application development.
Although it is possible to build user interfaces by using foundational Java Web technologies(such as Java servlets and JavaServer Pages) without a comprehensive framework designedfor enterprise Web application development, these core technologies can often lead to avariety of development and maintenance problems. More important, by the time the developers achieve a production-quality solution, the same set of problems solved by JSF will have been solved in a nonstandard manner. JavaServer Faces is designed to simplify the development of user interfaces for Java Web applications in the following ways:
• It provides a component-centric, client-independent development approach to building Web user interfaces, thus improving developer productivity and ease of use.
• It simplifies the access and management of application data from the Web user interface.
• It automatically manages the user interface state between multiple requests and multiple clients in a simple and unobtrusive manner.
• It supplies a development framework that is friendly to a diverse developer audience with different skill sets.
• It describes a standard set of architectural patterns for a web application.

[ Source : Complete reference:JSF ]


There are also situations where you can favor JSP over JSF. The application nature should be the deciding factor to choose the technology.

If you have a rich GUI interaction and lot of Java scripting needed then favor JSF. Basically if your GUI app architecture is like Component oriented & even driven like Swing then JSF is the best.

If the application is just a plain form submitting, not much of GUI interaction needed, then JSP could do well if learning a new tech is an overhead and also complex framework is unnecessary.


Servlet - it's java server side layer.

  • JSP - it's Servlet with html
  • JSF - it's components base on tag libs
  • JSP - it's converted into servlet once when server got request.

that is true that JSP is converted into servlet at the time of execution, and JSF is totally new thing in order to make the webpage more readable as JSF allows to write all the programming structures in the form of tag.


Java Server Pages (JSP) is java technology which enables Web developers and designers to rapidly develop and easily maintain, information-rich, dynamic Web pages that leverage existing business systems. JSP technology separates the user interface from content generation, enabling designers to change the overall page layout without altering the underlying dynamic content.

Facelets is the first non JSP page declaration language designed for JSF (Java Server Faces) which provided a simpler and more powerful programming model to JSF developers as compare to JSP. It resolves different issues occurs in JSP for web applications development.

Here is a table that compares the features of scriplets and facelets:

enter image description here Source


The basic difference between Servlets and JSP is that in Servlets we write java code and in that we embed HTML code and there is just reverse case with JSP . In JSP we write HTML code and in that we embed java code using tags provided by JSP.


JSP:means HTML+Java Code:

JSP have it's own life cycle jsp_init() jsp_service() jsp_destroy

After first request JSP convert to .java file. There is three type of tag we are using
1.)Scriptless

<%  %>

Here developer can declare all those things which developer want to take the data

2.)Expression tag

<%=  %>

Here developer can use some print related data

3.)Declaration

<!% %>

Here developer can declare some method related data.

Servlet:

Servlet have it's own life cycle.

init()
service()
destroy()

After first request container will read the data from web.xml file then after out welcome fill will be display.
Now onward after performing action it will search the url and after this process it will search the particular servlet there it self. service operation will perform.

JSF:

JSF have it's own ui and it's life cycle can perform in six way,

A)Restore view phase
B)Apply request values phase
C)Process validations phase
D)Update model values phase
E)Invoke application phase
F)Render response phase

For ui here for table here we are using panel grid and there is different faces for this that is.

Rich Faces
Prime Faces.

Jsp is also having in built servlet code which don't need any external compilation it can be run directly run. Changes will take effect in jsp directly in a browser.

Servlet need to be compiled (i.e it will have specific class creation)

Jsf is a view component of MVC Framework


JSP stands for JAVA SERVER PAGE........ jsp is not a servlet. Jsp uses code and HTML tag both in itself you dont need to make a HTML and a servlet seprately.Jsp are playing magnificent role in web application. Servlet is a java class plays an role to make your HTML page from static to dynamic .


JSPs are the View component of MVC (Model View Controller). The Controller takes the incoming request and passes it to the Model, which might be a bean that does some database access. The JSP then formats the output using HTML, CSS and JavaScript, and the output then gets sent back to the requester.


JSF is an advanced framework wherein its very easy to implement Model-View-Controller (MVC) based architecture for projects. Main advantage of JSF over JSP is the easy dynamic rendering of the components on the browser based upon conditions and easy integration of ajax events.

The front end of the JSF application i.e. xhtml files are the ones which are shown to the user via browser. These xhtml files internally invoke managed beans e.g. controllers wherein actual application logic is written.

The controllers internally invoke various services which communicate with database (using Hibernate or JPA API). This is how the flow happens in short.

JSF is also used in combination with RichFaces which is a framework for giving rich look and feel to your web application.

JSF + RichFaces + Hibernate/JPA is a good technology to learn for sure !


Servlets are the server side java programs which execute inside the web container. The main goal of the servlet is to process the requests received from the client.

Java Server Pages is used to create dynamic web pages. Jsp's were introduced to write java plus html code in a single file which was not easy to do in servlets program. And a jsp file is converted to a java servlet when it is translated.

Java Server Faces is a MVC web framework which simplifies the development of UI.

참고URL : https://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp

반응형