Title: Midterm
Course: CPS 278: Server Side Java ~ For IGNITE Review > Section: Assignments & Tests

Q: Many of the following lines will generate a JSP compile error.

Pick the line number which compiles properly.
- line 3
- line 4
- line 5
- line 6
A: line 6

Q: We derive our Java Web Servlets from this class.
- WebServlet
- ServerContext
- HttpRequest
- HttpServlet
A: HttpServlet

Q: Information stored in a user's browser containing information that the server would like remembered. Often this information is related to a user's session.
- dataStore
- ssl
- cookie
- token
A: cookie

Q: This object is passed in the doGet routine and contains information passed as input from the user's browser.
- HttpServletResponse
- HttpServletRequest
- HttpServletContext
- HttpGetData
A: HttpServletRequest

Q: You want to override this method to handle Get Method Form requests
- getData
- doGet
- getParameter
- getParameterValues
A: doGet

Q: Which type of objects can store attributes using the setAttribute method
(Pick 2)
- ServletConfig
- HttpServletRequest
- ServletResponse
- HttpSession
- Cookie
A: HttpServletRequest; HttpSession

Q: This is the name of the Java Based Web server that we obtained from the Apache Organization
- Jakarta
- JavaServe
- J2EE
- Tomcat
A: Tomcat

Q: This file uses XML to define the configuration of the Servlets that make up your project.
- server.xml
- config.xml
- WEB-INF
- web.xml
A: web.xml

Q: This html attribute tag is used inside of a Form to specify the URL location for the program that needs to process your Form.
- action
- url
- method
- doGet
A: action

Q: This class is obtained by calling the getWriter method from the Response object in a Servlet. This class is useful for sending Html back to the browser, and it contains methods print and println.
- ResponseBuffer
- BufferedWriter
- SendData
- PrintWriter
A: PrintWriter

Q: Given that req is an HttpServletRequest, which snippets of code create a session if one doesn't exist
(Pick 2.   Remember this is an open web test and there is online help for these classes)
- req.getSession()
- req.getSession(true)
- req.getSession(false)
- req.createSession()
- req.getNewSession()
- req.createSession(true)
- req.createSession(false)
A: req.getSession(); req.getSession(true)

Q: This protocol is used for communicating between a Browser and a Web server.
- Html
- Ftp
- Http
- Xml
A: Http

Q: This member function of the HttpServlet is used to process initialization code for your servlet.
- start
- run
- getServletContext
- init
A: init

Q: This member function of the HttpServletResponse class is used to send a cookie back to the browser.
- addCookie
- sendCookie
- send
- addRequest
A: addCookie

Q: This member function of the HttpServletRequest class can be used to obtain the values of your form input fields.
- getData
- getRequest
- getValue
- getParameter
A: getParameter

- Fragment A
- Fragment B
- Fragment C
- Fragment D
A: Fragment C

Q: This method can be called in your Servlet init routine to obtain configuration data.
- getData
- getConfig
- config
- getServletConfig
A: getServletConfig

Q: This member function of the HttpServletRequest is used to obtain all of the cookies destined to a particular web page.
- getConfig
- cookiesFetch
- getCookies
- doGet
A: getCookies

- Fragment A
- Fragment B
- Fragment C
- Fragment D
A: Fragment C

Q: Which are valid JSP implicit variables which can be accessed from from your JSP code?
(Pick 4)
- stream
- request
- context
- response
- out
- cookie
- session
A: request; response; out; session

Q: This class is used for creating and storing Web Session information.
- HttpSession
- HttpRequest
- SessionObject
- getAttribute
A: HttpSession

- JSP Scriptlet A
- JSP Scriptlet B
- JSP Scriptlet C
- JSP Scriptlet D
A: JSP Scriptlet C

Q: This Object is passed into the doGet method and is used for sending back information to the Client's browser
- Response
- SendResponse
- HttpServletSend
- HttpServletResponse
A: HttpServletResponse

Q: By default, how many instances of a servlet are created by a Servlet Container?
- One per request
- One per session
- One
- None of the above
A: One

Q: How do you store objects in a session object?
- put(String, Object)
- setAttribute(String, Object)
- addObject(String, Object)
- putObject(String, Object)
A: setAttribute(String, Object)

Q: How do you know if a session is alive? (Remember you can look this up in Online help for these classes)
- Look in the cookies.
- isSessionAlive() provides useful information
- Exception thrown if you try to create one when one already exists.
- getSession(false) provides useful information
A: getSession(false) provides useful information

Q: Where are cookies stored?
- On the server
- in web.xml
- On the client's browser
- in HTML
A: On the client's browser

Q: Where are session IDs stored?
- In Cookies
- in web.xml
- session IDs are not stored
- in HTML form fields
A: In Cookies

- JSP Fragment A
- JSP Fragment B
- JSP Fragment C
- Can't be done
A: JSP Fragment A

Q: According to the Http specification, which HTTP methods are NOT considered idempotent
(idempotent refers to a method that does not update the state of your server)
- GET
- POST
- HEAD
- PUT
A: POST

Q: This type of file is often used to capture the entire contents of a web application so that it can be installed on some other web site. We used this technique when we installed our Netbeans project on a Tomcat server running on Linux.
- zip file
- tar.gz file
- war file
- netbeans file
A: war file

Q: Using a MVC (Model View Controller), which of the following are you likely to do?
(Pick 5)
- Use a JSP page to handle the beginning part of the http request
- Use a Servlet to handle the beginning part of the http request
- Use a JSP page to handle that last part of the http request
- Use a Servlet to handle the last part of the http request
- Move as much of the Logic (i.e. the Model) into the Servlet class
- Move as much of the Logic (i.e. the Model) into the separate class outside of the Servlet.
- Use a RequestDispatcher to forward the http processing from a Servlet to a JSP page.
- Store information in the HttpServletRequest object with setAttribute
A: Use a Servlet to handle the beginning part of the http request; Use a JSP page to handle that last part of the http request; Move as much of the Logic (i.e. the Model) into the separate class outside of the Servlet.; Use a RequestDispatcher to forward the http processing from a Servlet to a JSP page.; Store information in the HttpServletRequest object with setAttribute

Q: In the lecture on MVC from the Murach textbook, we had a program that looked like:

In line 21, there is a call to setAttribute to store information in the request object.
What kind of data can be stored with setAttribute?
- Classes that have proper set and get methods
- Classes that extend the Attribute abstract class
- String classes
- Primitives or any class
- any class
A: any class

- It generates an error because of the unwanted '@' character
- It pulls in all of the contents of the file /includes/jokeInclude.jsp into this JSP compilation
- This is equivalent to the java import statement. For example: "import include.jokeInclude"
- JSP uses this when it wants to include C++ code.
A: It pulls in all of the contents of the file /includes/jokeInclude.jsp into this JSP compilation

- doPost
- doGet
- Tomcat will automatically pick either doGet or doPost depending on the current load queue
A: doPost

- doPost
- doGet
- Tomcat will automatically pick either doGet or doPost depending on the current load queue
A: doGet

- doPost
- doGet
- Tomcat will automatically pick either doGet or doPost depending on the current load queue
A: doGet

Q: If I have a lot of data to send from my form ( more than 2,000 bytes).  Which of the following forms should I choose :
- Form in line 1
- Form in line 2
- Form in line 3
- Form in line 4
- Form in line 5
- A form cannot send more than 2,000 bytes
A: Form in line 1

Q: This method is executed before any Servlet request is processed from doGet or doPost.
Often we do one time initialization in this method.
- start
- getInitParameter
- init
- initServlet
A: init

Q: An instance of this class can be created for each user that connects to a given web site.
The created object can then be used to store information related to the specific user.
- Session
- HttpSession
- Cookie
- HttpCookie
A: HttpSession

Q: This is a method in the HttpServletRequest class that returns an HttpSession.
- getSession
- session
- getHttpSession
- You need to call getCookie and then convert the Cookie to a Session
A: getSession

Q: This is a method in the HttpServletRequest class that allows a web program to fetch data saved in the browser that is used for programs that want to remember something.
- getInformation
- getBrowserInfo
- getHeaderInfo
- getCookies
A: getCookies

Q: This is a method in the HttpSession class that allows a web program to fetch data stored on the web server itself.
- getSession
- getAttribute
- getCookie
- getInitParameter
A: getAttribute

Q: This method in the HttpServlet class allows a web program to process data from an Html form that has an attribute named "method" and a value of "get".
- doMethod
- doPost
- doHeader
- doGet
A: doGet

Q: This class provides initialization parameters that are specific to a single Servlet.
- ServletInitParms
- ServletInit
- ServletConfig
- Config
A: ServletConfig

Q: This class contains data that is stored in a Client's browser.
- Cookie
- Session
- ClientInfo
- HttpInfo
A: Cookie

Q: Which of the following  XML tags in a web.xml file contains the name of a Servlet's code file.
- servlet-class xml tag on line 1
- servlet xml tag on line 2
- servlet-code xml tag on line 3
- servlet-file xml tag on line 4
A: servlet-class xml tag on line 1

Q: Which of the following  XML tags in a web.xml file contains a Servlet's Web address.
- http-address xml tag on line 1
- address xml tag on line 2
- web-url xml tag on line 3
- url-pattern xml tag on line 4
A: url-pattern xml tag on line 4

Q: Which of the following  XML tags in a web.xml file contains  a Servlet's configuration data.
- init xml tag on line 1
- init-param xml tag on line 2
- config-servlet xml tag on line 3
- config xml tag on line 4
A: init-param xml tag on line 2

Q: This XML tag in a web.xml file contains an internal name for the Servlet that allows us to associate the Servlet's class and initialization data with it's URL mapping.
- servlet xml tag on line 1
- class-name xml tag on line 2
- servlet-name xml tag on line 4
- servlet-id xml tag on line 5
A: servlet-name xml tag on line 4

Q: This class is used to contain all of the http information sent to the web server from the browser.
- Cookies
- HttpServletRequest
- HttpRequest
- UrlRequest
A: HttpServletRequest

Q: This is the top level class for defining a web Servlet.
- Servlet
- HttpSession
- HttpCookie
- HttpServlet
A: HttpServlet

Q: Forms have an attribute with this name that defines whether a GET or a POST is being used in request defined in the form.
- method
- action
- request
- request_type
A: method

Q: This method shows up in a JSP file that needs to do one time initialization before it starts fielding requests.
- init
- startJsp
- jspInit
- start
A: jspInit

Q: This XML file contains Tomcat configuration data related to which port numbers Tomcat is using.
- config.xml
- server.xml
- ports.xml
- server_ports.xml
A: server.xml

Q: This class contains all of methods needed for sending data back to a browser.
- Response
- HttpResponse
- SendHttp
- HttpServletResponse
A: HttpServletResponse

Q: An HTML form has an attribute with this name which defines the URL to send the request to.
- url
- http_request
- action
- method
A: action

Q: This method in the HttpSession class is used for saving information related to a specific session.
- storeAttribute
- setAttribute
- setResponse
- saveData
A: setAttribute

Q: This method in the HttpServlet class is used to process data related to a form using the POST method.
- doForm
- doMethod
- doGet
- doPost
A: doPost

Q: This method in the ServletConfig class is used to fetch configurable information from the web.xml file.
- getInitParameter
- getParameter
- getInit
- getConfig
A: getInitParameter