错题整理10.14

1.

HttpServlet容器响应Web客户请求流程如下:

1)Web客户向Servlet容器发出Http请求;

2)Servlet容器解析Web客户的Http请求;

3)Servlet容器创建一个HttpRequest对象,在这个对象中封装Http请求信息;

4)Servlet容器创建一个HttpResponse对象;

5)Servlet容器调用HttpServlet的service方法,这个方法中会根据request的Method来判断具体是执行doGet还是doPost,把HttpRequest和HttpResponse对象作为service方法的参数传给HttpServlet对象;

6)HttpServlet调用HttpRequest的有关方法,获取HTTP请求信息;

7)HttpServlet调用HttpResponse的有关方法,生成响应数据;

8)Servlet容器把HttpServlet的响应结果传给Web客户。

doGet() 或 doPost() 是创建HttpServlet时需要覆盖的方法.

2.

public Method[] getDeclaredMethods()返回类或接口声明的所有方法,包括public, protected, default (package) 访问和private方法的Method对象,但不包括继承的方法。当然也包括它所实现接口的方法。

public Method[] getMethods()返回类的所有public方法,包括其继承类的公用方法,当然也包括它所实现接口的方法。

3.

接口允许定义成员,但必须是常量。

4.

|  :检测ture;不具备短路功能,会检查每一个条件,表达式中只要一个ture 就整体返回true
|| :检测true;具备短路功能,一遇到true,就返回true;
&:检测false;同理上;
&&:检测false;同理上;

5.

以下代码定义了一个变量,如何输出这个变量的值?

 

A.<% String myBean = (String)pageContext.getAttribute(“stringBean”,PageContext.PAGE_SCOPE);
%>
<%=myBean%>
B.<bean:write name=“helloworld”/>
C.<bean:write name=“stringBean”/>
D.<%=stringBean%>
  • 选项:
    • 通过 pageContext(PageContext类的实例,提供对JSP页面所有对象以及命名空间的访问) 获取stringBean 的值,赋给 String 类型的变量 myBean,然后通过 Jsp 表达式 处理该值。
  • bean:define
    • 题目中的 Struts 的bean:define 标签定义了一个字符串变量 stringBean ,它的值为 helloworld。
  • bean:write
    • bean:write相当于 <%=request.getAttribute("something")%> 其中 something 是属性的名字。所以 B 错,C对。
  • 选项:
    • 通过Jsp 表达式 获取变量 stringBean 的值

猜你喜欢

转载自blog.csdn.net/a83370892/article/details/83051965