You are on page 1of 26

Introduction to JavaServer Pages

What is JSP Technology
• JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types. • Released in 1999 by Sun Microsystems. • JSP is similar to PHP, but it uses the Java programming language.

container to process JSP pages. • The JSP container is responsible for intercepting requests for JSP pages. .How does the JSP technology work? • JSP pages use XML tags and scriptlets written in the Java programming language to encapsulate the logic that generates the content for the page. • The web server needs a JSP engine ie.

• It knows how to understand the special elements that are part of JSPs.How does the JSP technology work? • A JSP container works with the Web server to provide the runtime environment and other services a JSP needs. .

• The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This is done by using the URL or JSP page which ends with . your browser sends an HTTP request to the web server.html.How does the JSP technology work? • JSP Processing: • As with a normal page. .jsp instead of .

.How does the JSP technology work? • JSP Processing: • The JSP engine loads the JSP page from disk and converts it into a servlet content. • This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code that implements the corresponding dynamic behavior of the page.

• A part of the web server called the servlet engine loads the Servlet class and executes it. .How does the JSP technology work? • JSP Processing: • The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine.

the servlet produces an output in HTML format. .How does the JSP technology work? • JSP Processing: • During execution. • The web server forwards the HTTP response to your browser in terms of static HTML content. which the servlet engine passes to the web server inside an HTTP response.

.How does the JSP technology work? • JSP Processing: • Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page.

How does the JSP technology work? .

and the actions based on user input into three separate components. . • In addition to dividing the application into three kinds of components. the MVC design defines the interactions between them. the presentation.JSP Application Design With MVC • MVC • The Model-View-Controller (MVC) pattern separates the modeling of the domain.

Often model objects retrieve data (and store data) from a database. Most often the views are created from the model data.JSP Application Design With MVC • MVC • The Model is the part of the application that handles the logic for the application data. . • The View is the parts of the application that handles the display of the data.

and send input data to the model. control user input. Typically controllers read data from a view.JSP Application Design With MVC • MVC • The Controller is the part of the application that handles user interaction. .

. because you can focus on one aspect a time.JSP Application Design With MVC • MVC Benefits • The MVC separation helps you manage complex applications. For example. you can focus on the view without depending on the business logic.

and the business logic in parallel. the controller logic.JSP Application Design With MVC • MVC Benefits • The MVC separation also simplifies group development. . • Different developers can work on the view.

JSP Application Design With MVC .

Why use MVC? Consider Model 1 Architecture .

Why use MVC? .

JSP Application Design With MVC .

JSP Application Design With MVC • MVC in Java Server Pages • If the design is architected correctly. a Web Designer could work with HTML on the JSP site without interfering with the Java developer. In fact it makes the initial implementation a little easier to write. • The Model/View/Controller architecture also works with JSP. .

. The business logic could be placed inside Java Beans.JSP Application Design With MVC • MVC in Java Server Pages • HTML content can be separated from the Java business objects. • JSP can also make use of Java Beans.

Every request goes through the controller who retrieves the necessary model object. . • The model may interact with other business entities such as databases or Enterprise Java Beans (EJB).JSP Application Design With MVC • MVC in Java Server Pages • The controller object is master Servlet.

. The JSP.JSP Application Design With MVC • MVC in Java Server Pages • The model object sends the output results back to the controller. is the view. • The controller takes the results and places it inside the web browser session and forwards a redirect request to a particular Java Server Page. in the case.

JSP Application Design With MVC • MVC in Java Server Pages • The controller has to bind a model and a view. . • We can have multiple controllers . but it could be any model and associated any view.but only one controls a section of the application at a time.

JSP Application Design With MVC • MVC in Java Server Pages • For example. they must communicate. . • Since only one controller can be in control at a given time. the administrator's functions may be controlled by one controller and the main logic controlled by another.

but the controller takes the simplified view representation and maps it to the models appropriately and also translates that response back to the view.JSP Application Design With MVC • MVC in Java Server Pages • There may also be multiple models . • The view never needs to know how the logic is implemented. .