You are on page 1of 4

1

Difference Between JSP & ASP


JSP 1. Java technology, JSP, from Sun Microsystems. 2. It can be executed on different Operating Systems like Windows/Linux/Unix/Solaris/Mac without any changes. 3. Its interoperable with EJB 4. Java Very Secure, very good way security can be implemented. 5. Embed Java code in HTML. 6. Its difficult to learn. 7. Speed is slow as compare to ASP very first time. ASP 1. ASP, Microsoft technology. 2. It can be executed on only windows, but nowadays Microsoft ASP.Net can be executed on different Operating systems, if MSIL is installed on that Operating System. 3. Its interoperable with DCOM+. 4. Not that much secure than Java. 5. Embed VB code in HTML. 6. Very easy to learn as compared to JSP. 7. Speed is fast as compared to JSP

JSP
How JSP page gets compiled, loaded and executed The Life Cycle of JSP First, the internal workings of the JSP engines can vary between servers. There is a general lifecycle that applies to all servers, but a few implementation differences may exist. That said, the lifecycle of JSPs is actually pretty simple: 1. A user makes an HTTP request (usually a GET or POST) to the server 2. If the request matches a registered pattern, the server calls the JSP page compilation servlet. Note that this registered pattern can usually be changed. Most often it's "*.jsp", but you could create other patterns or restrict the page compilation to certain directories on the server. 3. The Page Compilation servelet checks if the page actually exists. If not, it returns a 404 (not found) error 4. The Page Compilation servlet checks to see if it needs to regenerate/recompile the page. This determination is usually based on some server settings. In general, if a certain "timeout" setting has passed since the page was last accessed, it checks to see if the page source is newer than the last-generated servlet for it. If so, we need to regenerate. 5. If we need to regenerate the servlet for the JSP, the Page Compilation servlet translates the JSP code to Java servlet source. Then the Page Compilation servlet compiles the generated servlet. Compilation errors result in an error page being sent to the user. 6. If the servlet isn't currently loaded in the server (or has changed), the server loads it and calls its init() method, passing a ServletConfig object to describe the server and pass initialization parameters. 7. The server calls the servlet's service() method, passing an HttpServletRequest and HttpServletResponse. The generated servlet calls the code contained within the JSP, passing these parameters as request and response. 8. The server returns the resulting stream of (usually HTML) to the browser that asked for it. Finally, if the server decides to discard the generated servlet (usually when noone has requested it for longer than a preset timeout period), it calls the servlet's destroy() method, then drops the reference to that servlet (making it a candidate for garbage collection.) Keep in mind that JSPs are nothing but servlets in nicer clothing. They can do the exact same things as a servlet, but are generally easier to write.

How Do JSP Pages Work? A JSP page is basically a web page with traditional HTML and bits of Java code. The file extension of a JSP page is .jsp rather than .html or .htm, which tells the server that this page requires special handling that will be accomplished by a server extension or a plugin. When a JSP page is called, it will be compiled (by the JSP engine) into a Java servlet. At this point the servlet is handled by the servlet engine, just like any other servlet. The servlet engine then loads the servlet class (using a class loader) and executes it to create dynamic HTML to be sent to the browser, as shown in Figure 1. The servlet creates any necessary object, and writes any object as a string to an output stream to the browser. User Request Form

Request
JSP Engine Web Server Server Extension

Server Response Client

Response

Servlet Engine

Server-Side

Figure 1: Request/Response flow calling a JSP page The next time the page is requested, the JSP engine executes the already-loaded servlet unless the JSP page has changed, in which case it is automatically recompiled into a servlet and executed. When you type any URL in your browser like http://localhost:8080/login.jsp First time, the jsp file e.g. login.jsp page is first converted to login.java file (Servlet), then compiled and executed. Second time, if no JSP changes, Java file compiled version is available, so no translation from .jsp to java and no compilation needed, only execution of file requires, performance is good at second time.

Difference Between JSP and Servlets JSP and Servlets are technically same but following difference is made for usage: JSP is simpler code and is used to display the results generated from the Servlet. JSP pages are actually compiled into Servlets and cached when the java application server is in use. JSP is Java code embedded in HTML; the Java code is compiled (if necessary) and run by the container on the server and the client only sees the results of that code's execution mixed in appropriately with the html. JSP is used for display purpose, easy to write down display logic in HTML, easy for designer to work, used for view purpose, but at the time of execution JSP is converted into Servlet. JSP pages can contain complex business logic or database queries, but this is not good programming practice. A Servlet is compiled Java code in the form of a class file. Servlets can be display content, but it is better to use them as a content rendering engine. Servlets are compiled pure Java class files (not mixed with HTML) that get posts from the client and send html to in return. Servlet used for controller, we can write display logic but it is tough to write, designer can not work on Servlet design, execution fast, performance is good, java logic can be written here, used mainly for controller. Servlet used for controller, we can write display logic but it is tough to write, designer can not work on Servlet design, execution fast, performance is good, java logic can be written here, used mainly for controller Servlets usually contain business logic or business rules and are also used to run database queries and get results.

You might also like