Struts培訓A組試題

來源:互聯網
上載者:User

 (1)假設在helloapp應用中有一個hello.jsp,它的檔案路徑如下:
%CATALINA_HOME%/webapps/helloapp/hello/hello.jsp   
那麼在瀏覽器端訪問hello.jsp的URL是什麼? (單選)
選項:
(A) http://localhost:8080/hello.jsp
(B) http://localhost:8080/helloapp/hello.jsp
(C) http://localhost:8080/helloapp/hello/hello.jsp

(2)假設在helloapp應用中有一個HelloServlet類,它位於org.javathinker包下,那麼這個類的class檔案應該放

在什麼目錄下? (單選)
選項:
(A) helloapp/HelloServlet.class
(B) helloapp/WEB-INF/HelloServlet.class
(C) helloapp/WEB-INF/classes/HelloServlet.class
(D) helloapp/WEB-INF/classes/org/javathinker/HelloServlet.class

(3)假設在helloapp應用中有一個HelloServlet類,它在web.xml檔案中的配置如下:
<servlet>
  <servlet-name> HelloServlet </servlet-name>
  <servlet-class>org.javathinker.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name> HelloServlet </servlet-name>
  <url-pattern>/hello</url-pattern>
</servlet-mapping>
那麼在瀏覽器端訪問HelloServlet的URL是什麼? (單選)
選項:
(A) http://localhost:8080/HelloServlet
(B) http://localhost:8080/helloapp/HelloServlet
(C) http://localhost:8080/helloapp/org/javathinker/hello
(D) http://localhost:8080/helloapp/hello

(4)客戶請求訪問HTML頁面與訪問Servlet有什麼異同?(多選)
選項:
(A)相同:都使用HTTP協議
(B)區別:前者Web伺服器直接返回HTML頁面,後者Web伺服器調用Servlet的方法,由Servlet動態產生HTML頁面
(C)相同:前者Web伺服器直接返回HTML頁面,後者Web伺服器直接返回Servlet的原始碼。
(D)區別:後者需要在web.xml中配置URL路徑。
(E)區別:前者使用HTTP協議,後者使用RMI協議。

(5)HttpServletRequest對象是由誰建立的?(單選)
選項:
(A)由Servlet容器負責建立,對於每個HTTP請求, Servlet容器都會建立一個HttpServletRequest對象
(B)由JavaWeb應用的Servlet或JSP組件負責建立,當Servlet或JSP組件響應HTTP請求時,先建立

HttpServletRequest對象

(6)從HTTP請求中,獲得請求參數,應該調用哪個方法? (單選)
選項:
(A)調用HttpServletRequest對象的getAttribute()方法
(B)調用ServletContext對象的getAttribute()方法
(C)調用HttpServletRequest對象的getParameter()方法

(7)ServletContext對象是由誰建立的?(單選)
選項:
(A)由Servlet容器負責建立,對於每個HTTP請求, Servlet容器都會建立一個ServletContext對象
(B)由JavaWeb應用本身負責為自己建立一個ServletContext對象
(C)由Servlet容器負責建立,對於每個JavaWeb應用,在啟動時,Servlet容器都會建立一個ServletContext對象

(8)jspForward1.jsp要把請求轉寄給jspForward2.jsp,應該在jspForward1.jsp中如何?? (單選)
選項:
(A) <a href=“jspForward2.jsp”>jspForward2.jsp </a>
(B) <jsp:forward page=“jspForward2.jsp”>

(9)當瀏覽器第二次訪問以下JSP網頁時的輸出結果是什麼?(單選)

<!% int a=0;     %>
<%
     int b=0;
     a++;
     b++;
%>

a:<%= a %> <br>
b:<%= b %>
  
選項:
(A)  a=0  b=0
(B) a=1  b=1
(c) a=2  b=1

(10)下面哪個說法是正確的? (單選)
選項:
(A) 對於每個要求訪問maillogin.jsp的HTTP請求,Servlet容器都會建立一個HttpSession對象
(B)每個HttpSession對象都有惟一的ID。
(C)JavaWeb應用程式必須負責為HttpSession分配惟一的ID

(11)如果不希望JSP網頁支援Session,應該如何辦? (單選)
選項:
(A) 調用HttpSession的invalidate()方法
(B) <%@ page session= “false/">

(12)在標籤處理類中,如何訪問session範圍內的共用資料? (多選)
選項:
(A)在TagSupport類中定義了session成員變數,直接調用它的getAttribute()方法即可。
(B)在標籤處理類TagSupport類中定義了pageContext成員變數,先通過它的getSession()方法獲得當前的

HttpSession對象,再調用HttpSession對象的getAttribute()方法。
(C)pageContext.getAttribute(“attributename”,PageContext.SESSION_SCOPE)

(13)在下面的選項中,哪些是TagSupport類的doStartTag()方法的有效傳回值? (多選)
選項:
(A) Tag.SKIP_BODY
(B) Tag.SKIY_PAGE
(C) Tag.EVAL_BODY_INCLUDE
(D) Tag.EVAL_PAGE

(14)以下代碼能否編譯通過,假如能編譯通過,運行時得到什麼列印結果?(單選)
request.setAttribute(/"count/",new Integer(0));
Integer count = request.getAttribute(/"count/");
選項:
A)不能編譯通過  B)能編譯通過,並正常運行 
C) 編譯通過,但運行時拋出ClassCastException

答案:
(1)C (2)D  (3)D  (4)A,B,D  (5)A  (6)C  (7)C  (8)B  (9)C   (10)B
(11)B  (12)B,C  (13)A,C  (14)A

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.