java - What is the difference between JSF, Servlet and JSP? -


how jsp , servlet related each other? jsp kind of servlet? how jsp , jsf related each other? jsf kind of prebuild ui based jsp asp.net-mvc?

jsp (javaserver pages)

jsp java view technology running on server machine allows write template text in client side languages (like html, css, javascript, ect.). jsp supports taglibs, backed pieces of java code let control page flow or output dynamically. well-known taglib jstl. jsp supports expression language, can used access backend data (via attributes available in page, request, session , application scopes), in combination taglibs.

when jsp requested first time or when web app starts up, servlet container compile class extending httpservlet , use during web app's lifetime. can find generated source code in server's work directory. in example tomcat, it's /work directory. on jsp request, servlet container execute compiled jsp class , send generated output (usually html/css/js) through web server on network client side, in turn displays in web browser.

servlets

servlet java application programming interface (api) running on server machine, intercepts requests made client , generates/sends response. well-known example httpservlet provides methods hook on http requests using popular http methods such get , post. can configure httpservlets listen http url pattern, configurable in web.xml, or more java ee 6, @webservlet annotation.

when servlet first requested or during web app startup, servlet container create instance of , keep in memory during web app's lifetime. same instance reused every incoming request url matches servlet's url pattern. can access request data httpservletrequest , handle response httpservletresponse. both objects available method arguments inside of overridden methods of httpservlet, such doget() , dopost().

jsf (javaserver faces)

jsf component based mvc framework built on top of servlet api , provides components via taglibs can used in jsp or other java based view technology such facelets. facelets more suited jsf jsp. namely provides great templating capabilities such composite components, while jsp offers <jsp:include> templating, you're forced create custom components raw java code (which bit opaque , lot of tedious work in jsf) when want replace repeated group of components single component. since jsf 2.0, jsp has been deprecated view technology in favor of facelets.

as being mvc (model-view-controller) framework, jsf provides facesservlet sole request-response controller. takes standard , tedious http request/response work hands, such gathering user input, validating/converting them, putting them in model objects, invoking actions , rendering response. way end jsp or facelets (xhtml) page view , javabean class model. jsf components used bind view model (such asp.net web control does) , facesservlet uses jsf component tree work.

related questions


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -