24-02-25 ----------- Q)What is JSP? =>JSP is a Java based web technology from Sun Microsystems. Q)What is the purpose of JSP technology? =>JSP technology is used to develop Java based dynamic websites. OR =>In Java based web application development JSP technology is used. Q)What is a jsp? =>A jsp is a dynamic web resource that enahances the functionality of the web server. =>A jsp is a JSP Container managed web server side piece of code(server side program). =>A jsp is a web component. =>A jsp is a a text file with any name but with ".jsp extension. Q)What can a jsp do in a Java web application? =>All that a servlet can do. Q)Can a jsp replace a servlet? =>Yes. But it will not do. Note:- In fact, each use-case is implemented using a servlet and a jsp together. Q)When there is already Servlet technology, what was the need of JSP technology? =>servlets are weak in presentation. JSP is excellent in that. Q)What are the constituents (contents) of a jsp? A jsp=HTML code+Scripting elements+Java code Q)What is the life cycle of a jsp? =>JSP container controls the life cycle of a jsp. =>jsp development is nothing but instead of we developing a servlet, asking the JSP container to write a servlet for us. 1)translation phase 2)compilation phase 3)instantiation phase 4)initialization phase 5)servicing phase 6)destruction phase Q)Explain about Scripting elements. =>JSP Scripting elements are those JSP elements using which, Java code is directly embeded into a jsp. =>Scripting elements are of 3 types. 1.)declaration 2.)expression 3.)scriptlet =>JSP declaration is one of the three JSP scripting elements. =>It is used to place Java code directly within the source code of a jsp. =>A JSP declaration starts with <%! and ends with %> =>With in a JSP declaration we can place Java variables and Java methods. =>During translation phase, Java variables and Java methods of the JSP declaration become the members of the page implementation class. i.e. container generated servlet. expression ------------- =>JSP expression is one of the three JSP scripting elements. =>It is used to place Java code directly within the source code of a jsp. =>A JSP expression starts with <%= and ends with %> =>Within a JSP expression we can write only one Java expression(that too without semi colon). For eg. a.) <%= a+b %> b.) <%= request.getParameter("username") %> c.) <%= sum %> =>During translation phase, Java expression of a JSP expression is placed in the servicing method of page implementation class. =>We can have any number of JSP expressions in a jsp. In the same order their Java code will be placed in the servicing method. =>When a JSP expression is executed, 2 things happen in the background. 1.)Java expression is evaluated. 2.)evaluated value is written to the browser stream. scriptlet ----------- =>JSP scriptlet is one of the three JSP scripting elements. =>It is used to place Java code directly within the source code of a jsp. =>A JSP scriptlet starts with <% and ends with %> =>We can place free form of Java code in a JSP scriptlet. i.e. during servlet programming whatever Java code we write in servicing method to implement the use-case, all that Java code we can write in a JSP scriptlet. For eg. <% String a=request.getParameter("t1"); String b=request.getParameter("t2"); int n1=Integer.parseInt(a); int n2=Integer.parseInt(b); ... %> =>During translation phase, Java code of a JSP Scriptlet is placed in the srvicing method of page implementation class. Q)What are the frequently used implicit objects in a jsp? 1)request 2)application 3)session 4)out Q)Modify "additionapplication" so as to make use of a jsp in place of the servlet. jspadditionapplication numbers.html addition.jsp WEB-INF web.xml http://localhost:8081/jspadditionapplication/numbers.html numbers.html ----------------

Addition user interface

NUMBER 1

NUMBER 2

web.xml --------- Note:- jsp need not be registered with the container. addition.jsp ------------

Addition user interface

NUMBER 1

NUMBER 2

Q)Explain about MVC architecture of Java web application development. =>A Java web application contains 3 different logics 1)flow control logic(application loigc) 2)data accessing and data processing logic 3)Presentation logic(output generation logic) =>In MVC(Model, View, Controller) architecture of attending a client request, =>data accessing and data processing logic are implemented in a Java object known as Model. =>Model is divided into two components. 1)Business Component(service Object) 2)Data Access Object => Flow control logic(application logic) is implemented in controller. =>A servlet acts as a controller as per MVC architecture. =>What user sees is view. View Component produces the view for the users. In a Java web application, a jsp is used as a view component. MVC Diagram 1:- controller receiving the client request 2:- controller asks the model for processed data 3:- Model gives processed data to the controller 4:- controller swithing the control to the view component 5:- view component producing the response page for the client