Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 (25 marks) a) Explain ONE (1) advantage of JSP over Servlet. (2 marks) b) Analyse Program 2.1 until 2.3 in the code segment

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 2 (25 marks) a) Explain ONE (1) advantage of JSP over Servlet. (2 marks) b) Analyse Program 2.1 until 2.3 in the code segment below that consists of FOUR (4) errors. Trace the errors and propose the correct statements. Use format in Table 2a below to write your answer. (6 marks) JSP element type: directive, declaration, scriptlet, expression, action // Program 2.1 - scripting 1.jsp 2 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Program 2.2 - scripting2.jsp JSP Page // Program 2.3 - error.jsp JSP Page 20 21 22 23 24 25 26 27 28 29 30 32 32 33 Table 2a: Errors and the corrections. Line no The correct JSP element type Corrected statement 4 c) JSP lifecycle is defined as translation of JSP page into servlet as a JSP page needs to be converted into servlet first in order to process the service requests. Assuming that you have corrected Program 2.1 above. (6 marks) (i) Analyse Program 2.4 below and map the code of JSP page in Program 2.1 (scripting 1.jsp) into Servlet in Program 2.4 (scripting/_jsp.java). Fill in the blanks below. Note: Write "Not Applicable" where necessary, (ii) Based on your answer in (i), justify your answer. 7/ Program 2.4 - scriptingl_jsp.java package org.apache.jsp; import javax.servlet.'; import javax.servlet.http.; import javax.servlet.jsp.; public final class scriptingl_jsp extends org.apache.Jasper.runtime.httpJapBase implements org.apache.Jasper.runtime.jspSourceDependent (answer for 02.c.1.1) private static final JapFactory 1spxFactory JapFactory.getDefault.Factory () private statio java.util.List _jspx_dependants; private org.glassfish.jsp.api.Resource Injector 3spx_resource Injector; public java.util.List getDependants() return jspx_dependants; 1 public void japService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException PageContext page context = null; HttpSession session - null; ServletContext application- null; ServletConfig config = null; JspWriter out - null; Object page = this: JspWriter jspx_out - null; PageContext _jspx_page_context - null; try response.setContentType("text/html; charset=UTF-8"); response. set Header ("X-Powered-By","JSP/2.3"); pageContext - spxFactory.getPageContext(this, request, response, null, true, 8192, true); spx_page_context - pageContext; application - pageContext.getServletContext(); config - pageContext.getServletConfig(); session - pageContext.getSession(); out-pageContext.getOut(); S spx out-out jspx_resource Injector (org.glassfish.jap.api.Resource Injector) application.getAttribute("com.sun.appserv.jap.resource.injector": out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" JSP Page "); out.write(" "); out.write(" "); out.write(" (answer for 02.c.i.2) out.write(" "); out.write(" (answer for 22.c.i.3) out.write(" "); out.write(" (answer for 92.c.i.4) out.write(" "); out.write(" out.write(" "); out.write(" "); out.write(" "); } catch (Throwablet) if (!(t instanceof SkipPageException)) out - spx out; if (out ! - null && out.getBufferSize() - 0) out.clearBuffer(); 1 spx page_context null) jspx_page_context.handlePageException(t); else throw new ServletException(); 1 finally _jspx Factory.releasePageContextspx_page_context); 1 d) Assuming that the following list Car is stored in a session from a JSP file, as shown in the following code: // Program 2.5 - arraylist.jsp ArrayList list Car = new ArrayList(); 1 2 3 4 5 6 7 8 9 10 11 12 list.car.add("Proton"); listCar.add("Mitsubishi"); listCar.add("Nissan"); listCar.add("Honda"); //add listCar into session session.setAttribute("car_list", listcar); 6 13 14 //display in view.jsp

click here to view in another page (through the use of session)

> 16 17 Write a segment of code for view.jsp that will extract the arraylist object (listCar) from the session and display the content of the arraylist using JSP Expression as in Figure 2a. (7 marks) Index Car Brand 1 Proton 2 Mitsubishi 3 Nissan 4 Honda Figure 2a e) Program 2.6 and 2.7 are code segments that show the files as an include file. 1) Complete the segment of code Program 2.8 and 2.9 below using JSP include directive or JSP include with suita include files either displayl.jsp or display2.jsp ii) From your answer in (i), justify your answer. (4 marks) 7/ Program 2.6 - display1.jsp

This is the content of my file

// Program 2.7 - display2.jsp 10 7 Program 2.8-index.jsp JSP Include Directive Page (answer for Q2.e.i.1) // Program 2.9-index.jsp JSP Include Action Pages/title> (answer for Q2.e.i.2) 8 9 10 11 12 13 14 15 ----- END OF QUESTIONS ---- 7 Question 2 (25 marks) a) Explain ONE (1) advantage of JSP over Servlet. (2 marks) b) Analyse Program 2.1 until 2.3 in the code segment below that consists of FOUR (4) errors. Trace the errors and propose the correct statements. Use format in Table 2a below to write your answer. (6 marks) JSP element type: directive, declaration, scriptlet, expression, action // Program 2.1 - scripting 1.jsp 2 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Program 2.2 - scripting2.jsp JSP Page // Program 2.3 - error.jsp JSP Page 20 21 22 23 24 25 26 27 28 29 30 32 32 33 Table 2a: Errors and the corrections. Line no The correct JSP element type Corrected statement 4 c) JSP lifecycle is defined as translation of JSP page into servlet as a JSP page needs to be converted into servlet first in order to process the service requests. Assuming that you have corrected Program 2.1 above. (6 marks) (i) Analyse Program 2.4 below and map the code of JSP page in Program 2.1 (scripting 1.jsp) into Servlet in Program 2.4 (scripting/_jsp.java). Fill in the blanks below. Note: Write "Not Applicable" where necessary, (ii) Based on your answer in (i), justify your answer. 7/ Program 2.4 - scriptingl_jsp.java package org.apache.jsp; import javax.servlet.'; import javax.servlet.http.; import javax.servlet.jsp.; public final class scriptingl_jsp extends org.apache.Jasper.runtime.httpJapBase implements org.apache.Jasper.runtime.jspSourceDependent (answer for 02.c.1.1) private static final JapFactory 1spxFactory JapFactory.getDefault.Factory () private statio java.util.List _jspx_dependants; private org.glassfish.jsp.api.Resource Injector 3spx_resource Injector; public java.util.List getDependants() return jspx_dependants; 1 public void japService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException PageContext page context = null; HttpSession session - null; ServletContext application- null; ServletConfig config = null; JspWriter out - null; Object page = this: JspWriter jspx_out - null; PageContext _jspx_page_context - null; try response.setContentType("text/html; charset=UTF-8"); response. set Header ("X-Powered-By","JSP/2.3"); pageContext - spxFactory.getPageContext(this, request, response, null, true, 8192, true); spx_page_context - pageContext; application - pageContext.getServletContext(); config - pageContext.getServletConfig(); session - pageContext.getSession(); out-pageContext.getOut(); S spx out-out jspx_resource Injector (org.glassfish.jap.api.Resource Injector) application.getAttribute("com.sun.appserv.jap.resource.injector": out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" "); out.write(" JSP Page "); out.write(" "); out.write(" "); out.write(" (answer for 02.c.i.2) out.write(" "); out.write(" (answer for 22.c.i.3) out.write(" "); out.write(" (answer for 92.c.i.4) out.write(" "); out.write(" out.write(" "); out.write(" "); out.write(" "); } catch (Throwablet) if (!(t instanceof SkipPageException)) out - spx out; if (out ! - null && out.getBufferSize() - 0) out.clearBuffer(); 1 spx page_context null) jspx_page_context.handlePageException(t); else throw new ServletException(); 1 finally _jspx Factory.releasePageContextspx_page_context); 1 d) Assuming that the following list Car is stored in a session from a JSP file, as shown in the following code: // Program 2.5 - arraylist.jsp ArrayList list Car = new ArrayList(); 1 2 3 4 5 6 7 8 9 10 11 12 list.car.add("Proton"); listCar.add("Mitsubishi"); listCar.add("Nissan"); listCar.add("Honda"); //add listCar into session session.setAttribute("car_list", listcar); 6 13 14 //display in view.jsp

click here to view in another page (through the use of session)

> 16 17 Write a segment of code for view.jsp that will extract the arraylist object (listCar) from the session and display the content of the arraylist using JSP Expression as in Figure 2a. (7 marks) Index Car Brand 1 Proton 2 Mitsubishi 3 Nissan 4 Honda Figure 2a e) Program 2.6 and 2.7 are code segments that show the files as an include file. 1) Complete the segment of code Program 2.8 and 2.9 below using JSP include directive or JSP include with suita include files either displayl.jsp or display2.jsp ii) From your answer in (i), justify your answer. (4 marks) 7/ Program 2.6 - display1.jsp

This is the content of my file

// Program 2.7 - display2.jsp 10 7 Program 2.8-index.jsp JSP Include Directive Page (answer for Q2.e.i.1) // Program 2.9-index.jsp JSP Include Action Pages/title> (answer for Q2.e.i.2) 8 9 10 11 12 13 14 15 ----- END OF QUESTIONS ---- 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Students also viewed these Databases questions