Java Web basics-java Training
1. Fill in blank questions (2 points for each blank, 30 points in total) 1. The default directory for publishing a Java Web Application on tomcat is the _ webapps ___ directory. 2. The deployment descriptor of the javaweb application refers to the web. xml _ file. 3rd, when using the login.html file of helloappapplication in Tomcat, the url to be written in the browser address bar is :__. 4. When the Servlet container starts each web application, it will create a unique ___ ServletContext _ object for it, which has the same lifecycle as the web application. 5. The response result of the request source component ___ will not be sent to the client, including _ Will _ to the client. ("Yes" or "no") 6. Mark in jsp that requests are forwarded :_________. 7. In JSP ,? Request? The built-in object represents the request message, the built-in response object represents the response message, and the ___ session _ built-in object represents the session. 8. If the fourth type of jdbc driver is used to connect to the database, the location of the jar file is "web application/_ WEB-INF/lib _______". 9. The Servlet container assigns a unique identifier for each HttpSession object, which is ___ SessionID ___. 10. In the mvc design mode, ___ javabean ___ is a model, ___ jsp is a view, and __servlet _ is a controller. Ii. multiple choice questions (2 points for each question, 30 points in total) 1. Which of the following options is not part of the http response? (? C )? A) Response Header B) response body c) Protocol version number d) Status line? 2. The body of the http request and response can be in any format. To ensure that the receiver can understand the data sent by the sender, the http protocol (d?) Protocol to regulate the data format of the body? A) FTP B) TCP c) HTTP d) MIME 3. Which two packages are used by the Servlet API? (Two answers) (ac) a) javax. servlet B) javax. servlet. jsp c )? Javax. servlet. http d) java. servlet 4. the lifecycle of a servlet does not include (B?) Method? A )? Init () method B )? Invalidate () method c )? Service () method d )? Destroy () method 5 (? C) The method can obtain the value of a form parameter: )? GetQuaryString () B )? GetPathInfo () c )? GetParameter () d )? GetAttribute () 6. Which of the following statements about redirection in servlet is false? (d) a) The sendRedirect () method B of the HttpServletResponse interface is used) the response result of the source component is not sent to client c )? After the sendRedirect () method, the code will still execute d) the source component and the target component share the ServletRequest object? 7. jsp commands do not include (c?) )? Page command B )? Taglib command c )? Import command d )? The syntax format of the include command 8 and java expressions in jsp is: ()? 9. The request forwarding operation can be performed (d ). A) sendRedirect () method B of the response built-in object in jsp) Mark c) include () method d of the RequestDispatcher object) forward () method 10 of the RequestDispatcher object ,(? D?) The built-in object can handle errors or exceptions in jsp page running. )? PageContext B )? Page c )? Session d )? Exception 11. Which of the following statements about jdbc APIS is false (? D?) )? The getConnection () method of the DriverManager interface can establish a connection with the database B )? The createStatement () method of the Connection interface can create a Statement object c )? The executeQuery () method of the Statement interface can send a select Statement to database d )? The ResultSet interface indicates result set 12 after the insert statement is executed. What value does the scope of the JavaBean obtain to share the javabean with multiple users, that is, the same lifecycle as that of the web application? (? D?) A) page B) request c) session d) application 13. Which of the following is NOT a tag related to javabean in JSP? (? B) 14. Which of the following statements about EL and JSTL are false? (D) a) EL is a concise data access language B) EL expression form: $ {var} c) the full name of JSTL is assumerver Pages Standard Tag Library d) JSTL only has one Core tag Library 15. All servlet filter classes must be implemented (?. A) javax. servlet. filter B) javax. servlet. servletConfig c) javax. servlet. servletContext d) javax. servlet. servlet 3. Programming question (40 points in total) 1. read two Request Parameters first and second in the first Servlet1 file, convert them to int values, and add them together, and stored in the request range, and then forward the request to the second Servlet2 .. The second Servlet2 file (the url is output), which outputs the result of the Servlet1 calculation to the customer. Add the following code according to the annotation. (23 points) public class Servlet1 extends HttpServlet {? Public void service (ServletRequest request, ServletResponse response )? Throws ServletException, IOException {? // Read two Request Parameters and convert them to int values? Int first = Integer. valueOf (request. getParameter ("first"). intValue (); ________ (3 points )? Int second = Integer. valueOf (request. getParameter ("second"). intValue (); ___ (3 points )? // Add the two numbers int sum = first + second; _____ (3 points )? // Add the sum attribute _? To the request object _? Request. setAttribute ("sum", String. valueOf (sum); ______ (3 points )? _? ServletContext context = getServletContext ();? RequestDispatcher dispatcher = context. getRequestDispatcher ("/output ");? Dispatcher. forward (request, response); _____ (5 points )?} Public class Servlet2 extends HttpServlet {? Public void service (ServletRequest request, ServletResponse response )? Throws ServletException, IOException {? // Read the sum calculated by Servlet1 in the request range? _? String sum = (String) request. getAttribute ("sum"); _________ (3 points )? // Output and? PrintWriter out = response. getWriter ();? Out. print ("the sum is" + sum); _________ (3 points )?} 2. Write a user table for JSP Access to the Access database and display all records. The ODBC data source is named test and the driver class is named "sun. jdbc. odbc. jdbcOdbcDriver, the url to connect to the database is: "jdbc: odbc: test ". In the user table, the name field is of the text type, and the password is of the numerical type. Connect to the database code (6 points), send the query statement code (4 points), and process the result set code (7 points) (17 points in total)