source

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

goodcode 2022. 8. 15. 21:09
반응형

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

몇 가지 질문이 있습니다.다음은 다음과 같습니다.

  1. JSP와 Servlet은 어떻게 관련되어 있습니까?
  2. JSP는 서블릿의 일종입니까?
  3. JSP와 JSF는 어떻게 관련되어 있습니까?
  4. JSF는 ASP와 같은 사전 빌드 UI 기반의 JSP입니다.NET-MVC?

JSP(Java Server 페이지)

JSP는 클라이언트 측 언어(HTML, CSS, JavaScript 등)로 템플릿텍스트를 쓸 수 있는 서버 머신 상에서 실행되는 자바 뷰 테크놀로지입니다.JSP는 페이지 흐름 또는 출력을 동적으로 제어할 수 있는 Java 코드에 의해 백업되는 taglibs를 지원합니다.잘 알려진 taglib은 JSTL입니다.JSP는 주로 taglib와 조합하여 백엔드 데이터(페이지, 요청, 세션 및 응용 프로그램스코프에서 사용 가능한 속성)에 액세스하기 위해 사용할 수 있는 Expression Language도 지원합니다.

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

서블릿

Servlet은 서버 머신에서 실행되는 Java Application Programming Interface(API; 응용 프로그램프로그래밍 인터페이스)로 클라이언트의 요구를 대행 수신하여 응답을 생성/전송합니다.잘 알려진 예는HttpServlet다음과 같은 일반적인 HTTP 방식을 사용하여 HTTP 요구에 후크하는 방법을 제공합니다.GET그리고.POST를 설정할 수 있습니다.HttpServlet특정 HTTP URL 패턴을 리슨합니다.이 패턴은 로 설정할 수 있습니다.web.xmlJava EE 6에서는, 또는 그 보다 최근에는,@WebServlet주석입니다.

서블릿이 처음 요청되었을 때 또는 웹 앱 시작 중에 서블릿 컨테이너가 해당 서블릿의 인스턴스를 생성하여 웹 앱의 수명 동안 메모리에 보관합니다.URL이 서블릿의 URL 패턴과 일치하는 모든 수신 요청에 대해 동일한 인스턴스가 재사용됩니다.에 의해 요청 데이터에 액세스하고 에 의해 응답을 처리할 수 있습니다.두 개체는 오버라이드된 메서드 내에서 메서드 인수로 사용할 수 있습니다.HttpServlet,예를 들어doGet()그리고.doPost().

JSF(Java Server 면)

JSF는 Servlet API 위에 구축된 컴포넌트 기반 MVC 프레임워크로, JSP 또는 페이스렛과 같은 다른 자바 기반 뷰 기술에서 사용할 수 있는 태그립을 통해 컴포넌트를 제공합니다.페이스렛은 JSP보다 JSF에 훨씬 적합합니다.반면 JSP기본적으로는<>를 제공하도록 할 때 단일 com과 구성 요소 중 그룹을 새로 바꾸고 싶어 회가 Java코드(꽤 긴 불투명하고 지루한 작업의 많은)으로 고객 구성품을 창작할 수 밖에 있는 즉,;JSF에 템플 레이팅에, 복합 구성 요소와 같은 위대한templating 능력;jsp:include&gt을 제공한다.ponent.JSF 2.0 이후 JSP는 페이스렛을 선호하는 뷰 기술로서 폐지되었습니다.

주의: JSP 자체는 권장되지 않습니다.JSF와 JSP의 조합은 권장되지 않습니다.

주의: JSP는 Taglibs, 특히 (Tag File) 변종에 의한 뛰어난 템플릿 작성 능력을 갖추고 있습니다.JSP템플릿과 JSF의 조합이 부족한 것입니다.

MVC(Model-View-Controller) 프레임워크로서 JSF는 유일한 요구 응답 컨트롤러로서 를 제공합니다.사용자 입력 수집, 검증/변환, 모델 객체에 배치, 액션 호출 및 응답 렌더링 등 모든 표준적이고 지루한 HTTP 요청/응답 작업이 사용자의 손에서 이루어집니다.이렇게 하면 기본적으로 View용 JSP 또는 Facellet(XHTML) 페이지와 JavaBean 클래스를 모델로 사용할 수 있습니다.JSF 컴포넌트는 뷰를 모델(ASP 등)과 바인드하기 위해 사용됩니다.NET Web 컨트롤은) 및FacesServletJSF 컴포넌트 트리를 사용하여 모든 작업을 수행합니다.

관련 질문

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

JSP 테크놀로지는 Java 테크놀로지 패밀리의 일부입니다.JSP 페이지는 서블릿으로 컴파일되어 JavaBeans 컴포넌트(빈) 또는 Enterprise JavaBeans 컴포넌트(엔터프라이즈빈)를 호출하여 서버에서 처리를 수행할 수 있습니다.이와 같이 JSP 테크놀로지는 웹 기반 애플리케이션을 위한 확장성이 뛰어난 아키텍처의 핵심 컴포넌트입니다.

https://jcp.org/en/introduction/faq 를 참조해 주세요.

A: Java Server Faces 기술은 웹 애플리케이션용 사용자 인터페이스를 구축하기 위한 프레임워크입니다.Java Server Faces 테크놀로지에는 다음이 포함됩니다.

UI 컴포넌트의 표시와 상태 관리, 이벤트 및 입력 검증 처리, 페이지 네비게이션 정의, 국제화 및 접근성 지원을 위한 API 세트입니다.

JavaServer Pages(JSP) 커스텀태그 라이브러리.JSP 페이지 내에서 JavaServer Faces 인터페이스를 나타냅니다.

JSP는 특수한 종류의 서블릿입니다.

JSF는 JSP에서 사용할 수 있는 태그 세트입니다.

브라우저/클라이언트 시점

JSP와 JSF는 모두 동일해 보이지만 애플리케이션별 요건에 따라 JSP는 요청 응답 기반 애플리케이션에 더 적합합니다.

JSF는 보다 풍부한 이벤트 기반 웹 애플리케이션을 대상으로 합니다.요청/응답보다 이벤트가 훨씬 더 세밀하게 보입니다.

서버의 관점

JSP 페이지는 servlet으로 변환되어 동작은 최소입니다.

JSF 페이지는 (특화된 Faces Servlet에 의해) 컴포넌트 트리로 변환되며 사양에 의해 정의된 컴포넌트 라이프 사이클을 따릅니다.

서블릿:

Java Servlet API를 통해 Java 개발자는 동적 웹 콘텐츠를 전달하기 위한 서버 측 코드를 작성할 수 있습니다.다른 자체 웹 서버 API와 마찬가지로 Java Servlet API는 CGI보다 향상된 성능을 제공하지만 몇 가지 중요한 추가 이점이 있습니다.서블릿은 Java로 코딩되었기 때문에 객체 지향(OO) 설계 접근 방식을 제공하며, 더 중요한 것은 모든 플랫폼에서 실행할 수 있습니다.따라서 Java를 지원하는 모든 호스트에 동일한 코드가 이식 가능했습니다.서블릿은 서버 측 웹 애플리케이션 개발에 널리 사용되는 기술이 되어 Java의 인기에 크게 기여했습니다.

JSP:

JSP는 서블릿을 기반으로 구축되어 웹 사용자 인터페이스용 다이나믹 HTML 콘텐츠를 대량으로 생성할 수 있는 보다 심플한 페이지 기반 솔루션을 제공합니다.JavaServer Pages는 웹 개발자와 디자이너가 동적인 Java 부분에 대한 특별한 태그를 사용하여 HTML 페이지를 쉽게 편집할 수 있도록 합니다.JavaServer Pages는 JSP 컨테이너라고 불리는 특별한 서블릿을 사용하여 동작합니다.이 서블릿은 웹 서버에 설치되어 모든 JSP 페이지뷰 요구를 처리합니다.JSP 컨테이너는 요청된 JSP를 서블릿코드로 변환하여 컴파일하고 즉시 실행합니다.같은 페이지에 대한 후속 요청은 해당 페이지의 런타임 서블릿을 호출하기만 하면 됩니다.서버상의 JSP 에 변경이 가해진 경우, 표시 요구에 의해서, 런타임 서블릿의 다른 변환, 컴파일, 및 재기동이 개시됩니다.

JSF:

JavaServer Faces는 웹 애플리케이션용 사용자 인터페이스를 구축하기 위한 표준 Java 프레임워크입니다.가장 중요한 것은 웹 애플리케이션 개발의 가장 어렵고 지루한 부분 중 하나인 사용자 인터페이스의 개발을 단순화하는 것입니다.
엔터프라이즈 웹 애플리케이션 개발을 위해 설계된 포괄적인 프레임워크 없이 기본 Java 웹 기술(Java servlet 및 Java Server Pages 등)을 사용하여 사용자 인터페이스를 구축할 수 있지만 이러한 핵심 기술은 종종 개발 및 유지 보수 문제를 야기할 수 있습니다.더 중요한 것은 개발자들이 생산 품질의 솔루션을 달성할 때쯤에는 JSF에 의해 해결된 것과 동일한 일련의 문제들이 비표준적인 방식으로 해결된다는 것입니다.JavaServer Faces는 다음과 같은 방법으로 Java 웹 애플리케이션용 사용자 인터페이스 개발을 단순화할 수 있도록 설계되었습니다.
• 웹 사용자 인터페이스를 구축하기 위한 컴포넌트 중심의 클라이언트 독립적인 개발 접근 방식을 제공하여 개발자의 생산성과 사용 편의성을 향상시킵니다.
• 웹 사용자 인터페이스에서 애플리케이션 데이터에 대한 액세스 및 관리를 단순화합니다.
• 여러 요청과 여러 클라이언트 간의 사용자 인터페이스 상태를 간단하고 쉽게 자동으로 관리합니다.
• 다양한 스킬을 가진 다양한 개발자에게 친숙한 개발 프레임워크를 제공합니다.
• 웹 애플리케이션의 표준 아키텍처 패턴 세트를 설명합니다.

[출처 : 완전한 참조:JSF ]

JSF보다 JSP를 선호하는 경우도 있습니다.테크놀로지를 선택하기 위해서는 어플리케이션의 성질에 따라 결정되어야 합니다.

풍부한 GUI 인터랙션이 있어 Java 스크립트가 많이 필요한 경우 JSF를 선호합니다.기본적으로 GUI 앱 아키텍처가 컴포넌트 지향이고 Swing처럼 구동되는 경우 JSF가 가장 좋습니다.

어플리케이션이 GUI의 조작이 그다지 필요 없는 단순한 형식 제출인 경우, 새로운 기술을 학습하는 것이 오버헤드이며 복잡한 프레임워크가 불필요하다면 JSP는 도움이 될 수 있습니다.

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.

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.

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

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.

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 !

JSP stands for JavaServer Pages while JSF stands for JavaServer Faces. JSP is a technology that helps developers develop dynamic web pages using technologies like HTML, XML and similar other languages. JSF is a framework that helps developers develop user interfaces for server-side applications. Both these technologies are based on Java and they are primarily used for web-based applications. JSP is more like ASP or PHP except the fact that it is based on Java which means it uses Java programming language. Both the technologies are developed by Sun Microsystems. It is interesting to note that JSP 1.x versions used JSP as the default system for templating but JSP 2.x uses Facelets instead of JSP.

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 .

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.

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

반응형