当前位置:文档之家› j2ee测试题

j2ee测试题

NIIT内部测试题(J2EE)考试时间:120分钟总分:100分一、单选题(每题2分,共40分)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(D) http://localhost:8080/hello/hello.jsp2、假设在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.class3、假设在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/hello4、从HTTP请求中,获得请求参数,应该调用哪个方法?()(A)调用HttpServletRequest对象的getAttribute()方法(B)调用ServletContext对象的getAttribute()方法(C)调用HttpServletRequest对象的getParameter()方法(D)调用HttpSession对象的getParameter()方法5、当浏览器第二次访问以下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(D) a=2 b=26、J2EE 中,()类的()方法用于创建对话。

()a) HttpServletRequest、getSessionb) HttpServletResponse、newSessionc) HtttpSession、newInstanced) HttpSession、getSession7、给定一个 Servlet 的doGet方法中的代码片段,如下:request.setAttribute(“name”,”zhang”);response.sendRedirect(“http://localhost:8080/servlet/MyServlt”) 那么在 MyServlet 中可以使用()方法把属性 name的值取出来。

()a)String str=request.getAttribute(“name”);b)String str=(String)request.getAttribute(“name”);c)Object str=request.getAttribute(“name”);d)无法取出来8、以下()可用于检索session属性userid的值。

(只选一项)A.session. getAttribute (“userid”);B.session. setAttribute (“userid”);C.request. getParameter (“userid”);D.request. getAttribute (“userid”);9、在J2EE中,以下对RequestDispatcher描述正确的是()。

A.Jsp中有个隐含的对象diapatcher,它的类型是RequestDispatcherB.ServletConfig有一个方法:getRequestDispatcher可以返回RequestDipatcher对象C.RequestDipatcher 有一个方法:forward可以把请求继续传递给别的Servlet或者JSP界面D.JSP中有个隐含的默认对象request,它的类型是RequestDipatcher10、给定一个Servlet程序的代码片段,如下:( )Public void doPost(HttpServletRequest request,HttpServletResponse response) throwsServletException,IOException {request.getSession().getAttribute(“A”); //第二行}假定第二行返回的对象引用不是null,那么这个对象存储在()范围中。

A. pageB. sessionC. requestD. application11、给定一个Servlet的代码片段如下: ( )Public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{______out.println(“hi kitty!”);out.close();}运行次Servlet时输出如下:hi kitty!则应在此Servlet下划线处填充如下代码。

()A.PrintWriter out = response.getWriter();B.PrintWriter out = request.getWriter();C.OutputStream out = response.getOutputStream();D.OutputStream out = request.getWriter();12、给定某Servlet程序的片段如下,用户在浏览器地址栏中键盘键入正确的请求URL并回车后,在控制台上显示的结果是( ).public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException ,IOException{System.out.println("get");}public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException ,IOException{System.out.println("post");}A getB postC getpostD postget13、在JSP中,以下的page指令设置了使用的脚本语言是Java,且导入了java.rmi.*和java.util.*包.正确的是().a)<%@ page Language=“Java”,import=”java.rmi.*;java.uitl.* ”%”>b)<%@ page language=“Java” Import=”java.rmi.*,java.uitl.* ”%”>c)<%@ page language=“Java”;import=”java.rmi.*;java.uitl.* ”%”>d)<%@ page language=“Java” import=”java.rmi.* ,java.uitl.* ”%>14、在JSP中,test . jsp文件如下,试图运行时,将发生()。

<html><% String str = null; %>str is <%= str%></html>a)转译期有误b)编译Servlet源码时发生错误c)执行编译后的Servlet时发生错误d)运行后,浏览器上显示:str is null15、在一个Filter中,处理filter业务的是()方法。

a) dealFilter (ServletRequest request,ServletResponse response,FilterChain chain)b) dealFilter (ServletRequest request,ServletResponse response)c) doFilter (ServletRequest request,ServletResponse response, FilterChain chain)d) doFilter (ServletRequest request,ServletResponse response)16、在JSP页面中,保存数据的范围由小到大依次是a)pageContext,request,application,sessionb)pageContext,application,session,requestc)pageContext,request,session,applicationd)pageContext,session,request,application17、下列哪一项是在新窗口中打开网页文档。

相关主题