一组Struts的选择测试题附答案

来源:互联网 发布:民族证券交易软件 编辑:程序博客网 时间:2024/06/05 22:54

(1)假设在helloapp应用中有一个hell.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

c

(2)假设在helloapp应用中有一个HellServlet类,它位于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

d

(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

d

(4)客户请求访问HTML页面与访Servlet有什么异同?(多选)

a 相同:都使用HTTP协议

b 区别:前者Web服务器直接返回HTML页面,后者Web服务器调用Servlet的方法,由Servlet动态生成HTML页面

c 相同:前者Web服务器直接返回HTML页面,后者Web服务器直接返回Servlet的源代码。

d 区别:后者需要在web.xml中配置URL路径。

e 区别:前者使用HTTP协议,后者使用RMI协议。

a b d

(5)HttpServletRequest对象是由谁创建的?

a 由Servlet容器负责创建,对于每个HTTP请求,Servlet容器都会创建一个HttpServletRequest对象

b 由JavaWeb应用的Servlet或JSP组件负责创建,当Servlet或JSP组件相应HTTP请求时,先创建HttpServletRequest对象

a

(6)从HTTP请求中,获得请求参数,应该调用哪个方法?

a 调用HttpServletRequest对象的getAttribute()方法

b 调用ServletContext对象的getAttribute()方法

c 调用HttpServletRequest对象的getParamete()方法

c

(7)ServletContext对象是由谁创建的?

a 由Servlet容器负责创建,对于每个HTTP请求,Servlet容器都会创建一个ServletContext对象

b 由JavaWeb应用本身负责为自己创建一个ServletContext对象

c 由Servlet容器负责创建,对于每个JavaWeb应用,在启动时,Servlet容器都会创建一个ServletContext对象

c

(8)jspForward1.jsp要把请求转发给jspForward2.jsp,应该在jspForward1.jsp中如何实现?

a <a href="jspForward2.jsp">jspForward2.jsp</a>

b <jsp:forward page="jspForward2.jsp">

b

(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

c

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

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

b 每个HttpSession对象都有唯一的ID

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

b

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

a 调用HttpSession的invalidate()方法

b <%@ page session="false\" %>

b
(12)在标签处理类中,如何访问session范围内的共享数据?

a 在TagSupport类中定义了session成员变量,直接调用它的getAttribute()方法即可。

b 在标签处理类TagSupport类中定义了pageContext成员变量,先通过它的getSession()方法获得当前的HttpSession对象,再调用HttpSession对象的getAttribute()方法。

c pageContext.getAttribute("attributename",PageContext.SESSION_SCOPE)

b c

(13)在下面的选项中,哪些是TagSupport类的doStartTag()方法的有效返回值?

a Tag.SKIP_BODY

b Tag.SKIY_PAGE

c Tag.EVAL_BODY_INCLUDE

d Tag.EVAL_PAGE

a c

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

request.setAttribut("count",new Integer(0));

Integer count = request.getAttribute("count");

a 不能编译通过

b 能编译通过,并正常运行

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

a

0 0