java web复习题.docx

上传人:b****2 文档编号:2876407 上传时间:2023-05-04 格式:DOCX 页数:28 大小:27.74KB
下载 相关 举报
java web复习题.docx_第1页
第1页 / 共28页
java web复习题.docx_第2页
第2页 / 共28页
java web复习题.docx_第3页
第3页 / 共28页
java web复习题.docx_第4页
第4页 / 共28页
java web复习题.docx_第5页
第5页 / 共28页
java web复习题.docx_第6页
第6页 / 共28页
java web复习题.docx_第7页
第7页 / 共28页
java web复习题.docx_第8页
第8页 / 共28页
java web复习题.docx_第9页
第9页 / 共28页
java web复习题.docx_第10页
第10页 / 共28页
java web复习题.docx_第11页
第11页 / 共28页
java web复习题.docx_第12页
第12页 / 共28页
java web复习题.docx_第13页
第13页 / 共28页
java web复习题.docx_第14页
第14页 / 共28页
java web复习题.docx_第15页
第15页 / 共28页
java web复习题.docx_第16页
第16页 / 共28页
java web复习题.docx_第17页
第17页 / 共28页
java web复习题.docx_第18页
第18页 / 共28页
java web复习题.docx_第19页
第19页 / 共28页
java web复习题.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

java web复习题.docx

《java web复习题.docx》由会员分享,可在线阅读,更多相关《java web复习题.docx(28页珍藏版)》请在冰点文库上搜索。

java web复习题.docx

javaweb复习题

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文件中的配置如下:

HelloServlet

org.javathinker.HelloServlet

HelloServlet

/hello

那么在浏览器端访问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)jspForward2.jsp

(B)

forwardpage="jspForward2.jsp">

9.当浏览器第二次访问以下JSP网页时的输出结果是什么?

(单选)

%inta=0;%>

<%

intb=0;

a++;

b++;

%>

a:

<%=a%>

b:

<%=b%>

选项:

(A)a=0b=0

(B)a=1b=1

(C)a=2b=1

10.下面哪个说法是正确的?

(单选)

选项:

(A)对于每个要求访问maillogin.jsp的HTTP请求,Servlet容器都会创建一个HttpSession对象

(B)每个HttpSession对象都有惟一的ID。

(C)JavaWeb应用程序必须负责为HttpSession分配惟一的ID

11.如果不希望JSP网页支持Session,应该如何办?

(单选)

选项:

(A)调用HttpSession的invalidate()方法

(B)<%@pagesession="false">

12.以下代码能否编译通过,假如能编译通过,运行时得到什么打印结果?

(单选)

request.setAttribute(\"count\",newInteger(0));

Integercount=request.getAttribute(\"count\");

选项:

(A)不能编译通过

(B)能编译通过,并正常运行

(C)编译通过,但运行时抛出ClassCastException

13.J2EE中,类的方法用于创建对话。

(选择一项)

a)HttpServletRequest、getSession

b)HttpServletResponse、newSession

c)HtttpSession、newInstance

d)HttpSession、getSession

14.给定一个Servlet的doGet方法中的代码片段,如下:

request.setAttribute("name","zhang");

response.sendRedirect("http:

//localhost:

8080/servlet/MyServlt");

那么在MyServlet中可以使用方法把属性name的值取出来。

(单选)

a)Stringstr=request.getAttribute("name");

b)Stringstr=(String)request.getAttribute("name");

c)Objectstr=request.getAttribute("name");

d)无法取出来

15.以下可用于检索session属性userid的值。

(单选)

A.session.getAttribute("userid");

B.session.setAttribute("userid");

C.request.getParameter("userid");

D.request.getAttribute("userid");

16.在J2EE中,以下对RequestDispatcher描述正确的是。

(单选)

A.Jsp中有个隐含的对象diapatcher,它的类型是RequestDispatcher

B.ServletConfig有一个方法:

getRequestDispatcher可以返回RequestDipatcher对象

C.RequestDipatcher有一个方法:

forward可以把请求继续传递给别的Servlet或者JSP界面

D.JSP中有个隐含的默认对象request,它的类型是RequestDipatcher

17.在WEB应用程序的目录结构中,在WEB-INF文件夹外的文件为()。

(单选)

A.jsp文件

B.class文件

C.jar文件

D.web.xml文件

18.给定一个Servlet程序的代码片段,如下:

PublicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{

request.getSession().getAttribute("A");//第二行

}

假定第二行返回的对象引用不是null,那么这个对象存储在范围中。

(单选)

A.page

B.session

C.request

D.application

19.在J2EE中在servletl中的doGet和doPost方法中只有如下代码:

Request.setAttribute("jb","aPtech");

response.sendRedirect("http:

//localhost:

8080/servlet/Servlet2");

那么在Servlet2中使用可以把属性jb的值取出来。

(单选)

A.Stringstr=request.getAttribute("jb");

B.Stringsir=(String)request.getAttribute("jb");

C.Objectstr=request.getAttribute("jb");

D.取不出来

20.给定一个Servlet的代码片段如下:

publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{

______

out.println(“hikitty!

”);

out.close();

}

运行次Servlet时输出如下:

hikitty!

则应在此Servlet下划线处填充如下代码。

(单选)

A.PrintWriterout=response.getWriter();

B.PrintWriterout=request.getWriter();

C.OutputStreamout=response.getOutputStream();

D.OutputStreamout=request.getWriter();

21.在Servlet中,下列语句可以正确获取PrintWriter对象的是()。

(只选一项)

A.PrintWriterout=request.getWriter();

B.PrintWriterout=request.getPrintWriter();

C.PrintWriterout=response.getWriter();

D.PrintWriterout=response.getPrintWriter();

22.关于session的使用,下列说话正确的是。

(选择两项)

A.不同的用户窗口具有不同的session

B.不同的用户窗口具有相同的session

C.session可能超时间

D.Session永远不可能超时

23.在J2EE中,便用Resultset对象的next()方法移动光标时,如果超过界限,会抛出异常,该异常通常是。

(单选)

A.InterruptedExceptlon

B.AlreadyBoundExceptlon

C.SQLException

D.NetExcePtlon

24.在J2EE中,对于Httpservlet类的描述,错误的是()。

(单选)

A.我们自己编写的Servlet继承了Httpservlet类,一定需覆盖doPost或者doGet

B.HttpServlet类扩展了GenericServlet类,实现了GenericServlet类的抽象方法

C.HttpServlet类中处理客户请求和响应时所使用的两个接口是:

HttpServletRequest和HttpServletResponse.

D.我们自己编写的servlet继承了Httpservlet类,一般只需要覆盖doPost方法,不必覆盖servive()方法,因为一个service()方法会调用doPost或者doGet方法

25.Servlet中,HttpServletResponse的()方法用来把一个Http请求重定向到另外的URL。

(单选)

A.sendURL()

B.redirectURL()

C.sendRedirect()

D.redirectResponse()

26.在J2EE中,给定某Servlet的代码如下,编译运行该文件,以下陈述正确的是()。

(单选)

PublicclassServlet1extendsHttpServlet{

Publicvoidinit()throwsServletException{

}

Publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)ThrowsServletException,IOException{

PrintWriterout=response.getWriter();

Out.println(“hello!

”);

}

}

A编译该文件时会提示缺少doGet()或者dopost()方法,编译不能够成功通过

B编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中会看到输出文字:

hello!

C编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中看不到任何输出的文字

D编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中会看到运行期错误信息

27.J2EE中,HttpServletRequest类的()方法用返回与当前请求相关联的会话,如果没有,则返回null。

(选择一项)

AgetSession()

BgetSession(true)

CgetSession(false)

DgetSession(null)

 

28.在J2EE中,在web.xml中,有如下代码:

30

上述代码定义了默认的会话超时时长,时长为30()。

(单选)

A毫秒

B秒

C分钟

D小时

29.给定某Servlet程序的片段如下,用户在浏览器地址栏中键盘键入正确的请求URL并回车后,在控制台上显示的结果是.(单选)

publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException

{

System.out.println("get");

}

publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException

{

System.out.println("post");

}

Aget

Bpost

Cget

post

Dpost

Get

30.Servlet可以在以下三个不同的作用域存储数据。

A请求、会话和上下文

B响应、会话和上下文

C请求、响应和会话

D请求、响应和上下文

31.在J2EE中,重定向到另一个页面,以下()语句是正确的。

Arequest.sendRedirect(“http:

//www.jb-aptech.com.cn”);

Brequest.sendRedirect();

Cresponse.sendRedirect(“Http:

//www.jb–aptech.com.cn”);

Dresponse.sendRedirect();

32.在J2EE中,重定向到另一个页面,以下语句是正确的。

Arequest.sendRedirect(“http:

//www.jb-aptech.com.cn”);

Brequest.sendRedirect();

Cresponse.sendRedirect(“Http:

//www.jb–aptech.com.cn”);

Dresponse.sendRedirect();

33.http是一个协议

A.无状态

B.有状态

C.状态良好的

D.局域网

34.Servlet程序的入口点是

A、init()

B、main()

C、service()

D、doGet()

 

35.下列那个类是抽象类

AServletConfig

BHttpServlet

CCookie

DHttpServletRequest

36.Http协议的状态码表示文件没有创建

A200

B400

C500

D404

37.在JSP中,只有一行代码:

<%=A+B%>,运行将输出。

a)A+B

b)AB

c)113

d)没有任何输出,因为表达式是错误的

38.在JSP中,<%="1+4"%>将输出

a)l+4

b)5

c)14

d)不会输出,因为表达式是错误的

39.在JSP中,page指令的属性用来引入需要的包或类。

a)extends

b)import

c)languge

d)contentType

40.在JSP中,若要在JSP正确使用标签:

getKing/>,在jsp中声明的taglib指令为:

<%@tagliburi="/WEB-INF/myTags.tld"prefix="____">,下划线处应该是

a)x

b)getKing

c)myTags

d)king

41.在JSP中,test.jsp文件如下,试图运行时,将发生。

<%Stringstr=null;%>

stris<%=str%>

a)转译期有误

b)编译Servlet源码时发生错误

c)执行编译后的Servlet时发生错误

d)运行后,浏览器上显示:

strisnull

42.在JSP中,给定以下JSP代码片段,运行结果是。

<%intx=5;%>

<%!

intx=7;%>

<%!

intgetX(){

returnx;

}

%>

<%out.print("X1="+x);%>

<%out.print("X2="+getX());%>

a)X1=5X2=7

b)X1=5X2=5

c)X1=7X2=7

d)X1=7X2=5

43.在a.jsp中有代码片断如下:

loginName:

在b.jsp中加入代码,可以输出在a.jsp页面上输入的loginName的值。

a)<%=(String)request.getParameter("loginName")%>

b)<%=(String)request.gerAttribute("loginName")%>

c)<%Stringname=request.getParameter("loginname");

out.println(name);%>

d)<%Stringname-request.getAttribute("loginname");

out.println(name);%>

44.从HTTP请求中,获得请求参数,应该调用。

a)request对象的getAttribute()方法

b)request对象的getParameter()方法

c)session对象的getAttribute()方法

d)session对象的getParameter()方法

45.以下代码能否编译通过,假如能编译通过,运行时得到什么输出结果。

<%

request.setAttribute("count",newInteger(0));

Integercount=request.getAttribute("count");

%>

<%=count%>

a)编译不通过

b)可以编译运行,输出0

c)编译通过,但运行时抛出ClassCastException

d)可以编译通过,但运行无输出

46.下面关于JSP作用域对象的说法错误的是()。

a)request对象可以得到请求中的参数

b)session对象可以保存用户信息

c)application对象可以被多个应用共享

d)作用域范围从小到大是request、session、application

47.现在session中没有任何属性,阅读下面2个JSP中的代码,将分别输出。

<%

out.println(session.getAttribute("svse"));

%>

<%

session.invalidate();

out.println(session.getAttribute("svse"));

%>

a)null,异常信息

b)null,null,

c)异常信息,异常信息

d)异常信息,null

48.在JSP页面中,如果从一个源页面中通过

forwardpage=urlname/>将本页面请求转发至指定URL组件,则在该URL组件(JSP页面)中可处理的共享数据范围是

a)session

b)request

c)page

d)application

4

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2