Test
Web App midterm
Este test tiene tipos de pregunta que se abren en el reproductor de siempre.
Preguntas del test (49)
1processing requests

- Ay
2[blank_start]Servlet + JSP[blank_end]
Lower-level API that does less work for the programmer.
Provides a high degree of control over the HTML/CSS/JavaScript that’s returned to the browser.
The necessary background for understanding higher-level APIs.
[blank_start]JSF[blank_end]
Higher-level API that does more work for the programmer.
Makes it more difficult to control the HTML/CSS/JavaScript that’s returned to the browser.
[blank_start]Spring Framework[blank_end]
Higher-level API that does more work for the programmer.
Provides a high degree of control over the HTML/CSS/JavaScript that’s returned to the browser.
Great choice for large and small web applications.- AServlet + JSP
- BJSF
- CSpring Framework
3[blank_start]The Java Standard Edition ( Java SE )[blank_end] includes the Java Development Kit (JDK) and the Java Runtime Environment (JRE).
[blank_start]The Java Enterprise Edition ( Java EE )[blank_end]specification describes how web servers can interact with all Java web technologies.
[blank_start]Servlets[blank_end] store the Java code that does the server-side processing.
[blank_start]JavaServer Pages ( JSP )[blank_end] store the HTML and dynamically defines the user interface.
[blank_start]JavaServer Faces ( JSF )[blank_end] is a higher-level API that can be used instead of both servlets and JSPs.
[blank_start]Java Persistence API ( JPA )[blank_end] is a powerful and convenient API for working with databases- AThe Java Standard Edition ( Java SE )
- BThe Java Enterprise Edition ( Java EE )
- CServlets
- DJavaServer Pages ( JSP )
- EJavaServer Faces ( JSF )
- FJava Persistence API ( JPA )
4Two popular web servers:
Tomcat:
servlet/jsp engine includes web server
glassfish:
complete java ee application server- AVerdadero
- BFalso
5JSP Expressions start with <%= and end with %>.
May contain any Java expression
2 + 2 = <% 2 + 2 %>
<%
java for loop
%>- AVerdadero
- BFalso
6JSP Comments start with <%-- and end with --%>
difference with html comment:
HTML comments are sent to browser and visible inside of the page sources.
HTML comments do not hide JSP code from the compiler.- AVerdadero
- BFalso
7JSP Declarations start with <%! and end with %>
JSP Declarations are used to declare Java methods inside of JSP pages- AVerdadero
- BFalso
8JSP Directives start with <%@ and end with %>.
The directives are commonly used for the following:
Defining the page content for browsers: the content type and the encoding.
Importing Java packages.
Including other files into JSP pages.
Connecting to tag files and tag libraries
<%@page import="java.util.*"%>- AVerdadero
- BFalso
9Model 1 projects can contain:
- AJava Server Pages
- BHTML pages
- CStyle Sheets
- DImages
- ECustom Tags
- FJavaBeans
- GConfiguration Files
- HData Access Code
- ISQL files
- JLibrarys
10JavaBeans are Java public classes that satisfy the following three requirements:
1.Implement Serializable (or Externalizable) interface.
2.Provide public no-argument constructor.
3.Provide all necessary public get/set methods.- AVerdadero
- BFalso
11<jsp:useBean id="card" class="Card"/>
jsp:useBean tag instantiates the bean using its no-argument constructor if the instance does not exist
default scope is only this page
is NOT used in model 2 projects- AVerdadero
- BFalso
12JavaBean classes must use get/set methods for variables
- AVerdadero
- BFalso
13<jsp:useBean id="card" class="Card"/>
<p> ${card.number} </p>
the above uses useBean tag and id to be able to call class and its methods
it is possible to call set methods within JSP- AVerdadero
- BFalso
141.2.3.4.5.6.7.8.9.
- AServlet as controller/dispatcher
- BJSPs as Views
- CHTML pages as Views
- DStyle Sheets
- EImages
- FCustom Tags
- GJavaBeans as Model
- HConfiguration Files
- IData Access Code
- JSQL Files
15Servlets are Java classes that typically inherit from HttpServlet
In the NetBeans-generated project the processRequest method is called from the generated doGetand doPost methods that override the corresponding methods from the base class.- AVerdadero
- BFalso
16HttpServletRequest and HttpServletResponse objects are provided to doGet and doPost methods as parameters
ttpServletRequestobjects contain:
IP address of the browser,
previously set cookies,
data submitted with an input form,
browser information,
browser language settings, etc
HttpServletResponse objects contain:
generated web-pages,
new cookies,
error codes,
redirects, etc- AVerdadero
- BFalso
17JSP is a common but not the only choice for implementing views in Model-View-Controller (MVC) design pattern
Used only as templates to display data
Since JSPs (in MVC) do not acquire data, the data should be acquired elsewhere and made available to JSPs with attributes
request.setAttribute("card", card)
The attribute names in Model 2 work just like bean ids in Model 1- AVerdadero
- BFalso
18Servlet mapping:
url-pattern is the address (or addresses) of the servlet relative to the application folder (context path)
defines default address for web application- AVerdadero
- BFalso
19Forwarding:
happens entirely on server side
browsers not involved
Browsers obtain the pages, printed by JSPs, as the pages come directly from the servlet.
Request attributes are retained in forwarding: the request object, with its attributes, is passed to the JSP- AVerdadero
- BFalso
20Three ways to may a Servlet
1.Using @WebServlet annotation in the corresponding Servlet Java file
2.Using XML: <servlet> and <servlet-mapping> tags in web.xml file
3.Configuring dynamically (programmatically), using API calls in Java code
do NOT use more than 1 method for same application- AVerdadero
- BFalso
21@WebServlet annotation:
@WebServlet (urlPatterns= {"/input", "/process"})- AVerdadero
- BFalso
22The Default Servlet has the Servlet name “default”.
In mapping patterns, “/” means all addresses of the application, not only the default address of the application, but all of them.
If another Servlet is mapped to “/”, the CSS and image files will not be available, unless image and CSS folders are remapped explicitly later- AVerdadero
- BFalso
23[blank_start]Model[blank_end]:
Encapsulates core data and logic
Independent from views
can be implemented with JavaBeans and other classes
[blank_start]Views[blank_end]
Present the outputs to the user
Associated with a controller
Can be implemented with JSPs and other options
[blank_start]Controller[blank_end]
Receives inputs from the user
Processes the inputs translating them to model API
Connects model data to views and dispatches the views
Can be implemented with servlets or filters- AModel
- BViews
- CController
24Controller vs Dispatcher:
The servlet (or filter) is often combined with an additional helper class, containing methods called from the servlet.
Dispatcher code is usually reuseable between programs
Spring dispatcher is a servlet- AVerdadero
- BFalso
25String g = getInitParameter("greet");
request.setAttribute("greet", g);
Servlet initialization parameters are defined for specific servlets and available only inside of the servlets
Servlet initialization parameters are NOT global- AVerdadero
- BFalso
26Form Action:
<form method="post" action="InsertStudent.do"> address to submit form data
<input id="first" type="text" name="firstName"> request parameter name
<select id="prog" name="programName">
<option value="name1">name1</option> submitted value
in model 2 projects, its always a servlet address- AVerdadero
- BFalso
27HTTP GET method:
the default method to submit form data
sends form data through web address
NOT used for sensitive data
cannot be used with large data
will NOT show warnings
should NOT be used in resubmissions- AVerdadero
- BFalso
28HTTP POST method:
not default unless specified
dose not send through web address
should be used for sensitive data
protocols should be used to to submit confidential data
can use large data
shows warnings- AVerdadero
- BFalso
29retrieving data from form submit:
case "/InsertStudent.do":
StudentForm = new StudentForm();
form.setFirstName(request.getParameter("firstName");- AVerdadero
- BFalso
30Input data validation:
list errors
if errors is empty
request.setAttribute("student", form);
studentData.insert(form);
view = "confirmInsert";- AVerdadero
- BFalso
31<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
All Maven projects, using JSTL, must have this JSTL dependency copy-pasted into the Project Object Model (POM) file, pom.xml.
The pom.xml file is in "Project Files" folder of NetBeans projects.
Almost any project that uses JSP also uses JSTL- AVerdadero
- BFalso
32using JSTL in JSP:
<%@taglib import jstl... %>
<ul>
<c:forEach items="${errors}">
<li class="error">${e}</li>
</c:forEach>
</ul>
As the general rule, inserting a bean value requires ${ }
The temporary variable of the c:forEach loop picks the next string from the list of strings in each iteration, starting with the first.- AVerdadero
- BFalso
33conditions using JSTL:
<c:if test="${not empty errors}">
.....
</c:if>
The block inside of the c:if is excluded when the list is null or empty- AVerdadero
- BFalso
34displaying table rows in JSTL:
<c:forEach items="${students}" var="s"> students from setAttribute
<td>${s.firstName}</td>
</c:forEach>- AVerdadero
- BFalso
35Post Redirect Get pattern is used to avoid accidental resubmission of the data when a site visitor presses the browser reload button.
Post Redirect Get pattern involves three steps.
1.[blank_start]Post[blank_end]–The data is submitted to the server with post. The server processes the data, stores the data on the server side.
2.[blank_start]Redirect[blank_end]–The server sends a new address (redirection address) to the browser, usually, with some data id in the address.
3.[blank_start]Get[blank_end]–The browser retrieves the confirmation page, using the redirection address- APost
- BRedirect
- CGet
36Advantages of design pattern:
- AImproves software reusability
- BFaster development cycle
- CMore readable and maintainable code
- DOverall efficiency of software development
- EProvides common vocabulary to describe problems and solutions
- FLess repeated code or classes
- GBetter efficiency for delployment
37Low Coupling = Low dependency of components on each other by their lower structures, instead of their interfaces
High Cohesion= One component should perform one and only one well-defined job- AVerdadero
- BFalso
38The Single Responsibility Principle suggests that a module should be changed for one and only one reason only. Consequently, a module should have one and only one responsibility
A change inside of a module may require a lot of further changes inside of the same module, but few (ideally, no) changes outside of this module- AVerdadero
- BFalso
39The Open-Close Principle requires that new features are added to an existing module by extension, and not by modification
Little of a module code (ideally, no code) should be modified by adding a new feature- AVerdadero
- BFalso
40The Liskov Substitution Principle requires that Module A can be replaced with Module B, if Module B is a subtype of Module A
Well-defined contracts (interfaces) support the definition and help reduce the coupling between modules- AVerdadero
- BFalso
41The Interface Segregation Principle suggests that client modules should not have to deal with not used interface features
If the modules interacting with an interface are using few of the exposed functions, then the other ones should probably be moved to another interface, or even to new modules.
Avoid making interfaces that lead to a lot of empty methods in implementations
Interfaces should not have a lot of methods
Splitting an interface into two or more interfaces may improve the design- AVerdadero
- BFalso
42Dependency inversion principle(DIP)
High-level modules should not directly depend on low-level modules for their responsibilities. Both should depend on abstractions (interfaces).
Abstractions should not depend on details (implementations). Details should depend on abstractions- AVerdadero
- BFalso
43Inversion of Control(IoC) is a design methodology used to build loosely coupled systems by inverting the control of flow (of auxiliary tasks) from the main program to some other entity or a framework
- AVerdadero
- BFalso
44Hidden Inputs:
<input type="hidden" name="A" value="${problem.a}"/>
<input type="hidden" name="B" value="${problem.b}"/>
In order to check if the user's answer is correct, the program also needs to know that the randomly generated problem was 4x7.
The program inserts 4 and 7 as hidden inputs and receives them back
string A = request.getParamater("A");
b...
validate and output- AVerdadero
- BFalso
45Thymeleaf templates:
Thymeleaf templates belong to "resources > templates" folder.
They have extension ".html", and they are valid HTML files.
The templates (if done correctly) can be opened as files, and correctly displayed by browsers- AVerdadero
- BFalso
46@Controller:
Classes marked with @Controller are added by programmers as ordinary classes and edited
@RequestMapping ("/name.do")
The methods can be mapped to one or more addresses, as shown above (or not mapped at all).
return type of methods:
return "redirect:ListStudents.do"- AVerdadero
- BFalso
47ModelAndView objects:
new ModelAndView(viewName, modelName, attributeName)
ModelAndView object are used as return values of some mapped controller methods
model.addAttribute("form", form)- AVerdadero
- BFalso
48displaying ModelAndView values:
return new ModelAndView("output", "loan", loan);
<p th:text="${loan.value}"></p>
The body of this <p> tag will be replaced on the server with the proper value. The bodies of such tags are used to check the appearance of the page when the template is opened as the file, without running the application- AVerdadero
- BFalso
49th:object="${student}"
To avoid repetitions, the object name ("student", in this case) can be moved to an enclosing tag
th:if="${#lists.isEmpty(students)}
Content of tags can be displayed conditionally, with th:if, when the condition is true. The condition th:unless is the opposite to th:if
th:each="e: ${#fields.errors('*')}
iteratable data can be printed with th:each notation
th:href="@{addStudent.do}"
th:href links are used when the template is in an running application
th:action="@{removeStudent.do}"
th:action address is used when the template is in an running application- AVerdadero
- BFalso
Información
- Descripción
- Computer Science Test sobre Web App midterm, creado por Duncan Levings el 21/02/2019.
- Autor
- Duncan Levings
- Idioma
- English
- Visitas
- 1
- Etiquetas
- Valoración
- Aún sin valoraciones Valora este test