JavaEE常见面试题Word下载.docx
《JavaEE常见面试题Word下载.docx》由会员分享,可在线阅读,更多相关《JavaEE常见面试题Word下载.docx(18页珍藏版)》请在冰豆网上搜索。
Struts
1.struts1.2和struts2.0的区别?
如何控制两种框架中的单例模式?
struts1.2和struts2.0的对比
a、Action类:
struts1.2要求Action类继承一个基类。
struts2.0Action要求继承ActionSupport基类
b、线程模式
struts1.2Action是单例模式的并且必须是线程安全的,因为仅有一个Action的实例来处理所有的请求。
单例策略限制了Struts1.2Action能做的事情,并且开发时特别小心。
Action资源必须是线程安全的或同步的。
struts2.0Action为每一个请求产生一个实例,因此每有线程安全问题。
c、Servlet依赖
struts1.2Action依赖于ServletAPI,因为当一个Action被调用时HttpServletRequest和HttpServletResponse被传递给execut方法。
struts2.0Action不依赖于容器,允许Action脱离容器单独测试。
如果需要,Struts2Action仍然可以访问初始的Request和Response。
但是,其他的元素减少或者消除了直接访问HttpServletRequest和HttpServletResponse的必要性。
d、可测性
测试struts1.2Action的一个主要问题是execute方法暴露了ServletAPI(这使得测试要依赖于容器)。
一个第三方扩展:
strutsTestCase
提供了一套struts1.2的模拟对象来进行测试。
Struts2.0Action可以通过初始化、设置属性、调用方法来测试,“依赖注入”也使得测试更容易。
2.项目中为什么使用SSH
1.使用Struts是因为struts是基于MVC模式的,很好的将应非用程序进行了分层,使开发者更关注于业务逻辑的实现;
第二,struts有着
丰富的taglib,如能灵活运用,则能大大提高开发效率。
2.使用Hibernate:
因为hibernate为Java应用提供了一个易用的、高效率的对象关系映射框架。
hibernate是个轻量级的持久性框架,功能丰富。
3.使用Spring:
因为spring基于IoC(InversionofControl,反向控制)和AOP构架多层j2ee系统的框架,但它不强迫你必须在每一层
中必须使用Spring,因为它模块化的很好,允许你根据自己的需要选择使用它的某一个模块;
采用IoC使得可以很容易的实现bean的装配,提供了简洁的AOP并据此实现事务管理(TranscationManagment),等等
3.struts与spring是如何继承的
不懂题目之意:
是否是说的struts的action都继承自org.apache.struts.action.Action
而Spring中的继承就不清楚了。
4.struts如何实现国际化
以下以两国语言(中文,英文)为例:
1.在工程中加入Struts支持
2.编辑ApplicationResource.properties文件,在其中加入要使用国际化的信息,例如:
lable.welcome.china=Welcome!
!
3.创建英文资源文件ApplicationResource_en.properites
4.创建临时中文资源文件ApplicationResource_temp.properites例如:
lable.welcom.china=中国欢迎您!
5.对临时中文资源文件进行编码转换。
可以使用myeclipse的插件,也可以在dos下执行:
native2ascii-encodinggb2312ApplicationResource_temp.propertiesApplicationResource_zh_CN.properties
6.在jsp中加入struts的bean标记库<
%@tagliburi="
/WEB-INF/struts-bean.tld"
prefix="
bean"
%>
显示信息:
<
bean:
messagekey="
label.welcome.china"
>
可以在struts-config.xml文件中定义多个资源包,而每个资源包可使用key属性指定包的名称。
5.struts2.0的常用标签
1.往action里传值:
<
inputname="
userName"
type="
text"
class="
input6"
size="
15"
2.显示标签property用于输出指定值:
s:
propertyvalue="
userName"
/>
3.用于从页面往action中(user)的对象内传值:
textname="
user.userName"
id="
username"
4.判断<
if>
/s:
用于在页面中判断指定数据<
iftest="
userName==admin"
….<
else>
5.迭代<
iterator>
用于将List、Map、ArrayList等集合进行循环遍历
iteratorvalue="
userList"
user"
status="
u"
/a>
6.URL地址标签,<
url>
用于生成一个URL地址,可以通过URL标签指定的<
param>
子元素向URL地址发送请求参数
urlaction="
"
paramname="
value="
"
7.超链接<
ahref>
一般和<
标签一起使用,用于带多个参数。
ahref="
超链接<
8.set标签,用于将某个值放入指定的范围内。
例如application,session等。
setname="
scope=”request”/>
6.struts中怎么配置form-bean、action、tiles
此处配置的是struts1.2的
form-bean配置:
(在配置文件struts-config.xml中):
form-beans>
form-beanname="
type="
/form-bean>
/form-beans>
name:
指定form的名字;
type指定form的类型:
包名+类名;
action配置:
(在配置文件struts-config.xml中)
action-mappings>
actionpath="
attribute="
input="
name="
parameter="
scope="
request"
>
/action>
/action-mappings>
path:
请求Action的名字;
attribute:
form的名字,与form-bean中的name对应;
input:
输入页的路径;
name:
如果配置了attribute,name不起作用,与attribute一样;
parameter:
使用分发Action时,指定调用分发Action中的方法名;
scope:
Action的范围;
type:
Action的类型:
tites配置:
1.新建一个tiles-defs.xml文件,并在其中做如下配置:
?
xmlversion="
1.0"
encoding="
UTF-8"
DOCTYPEtiles-definitionsPUBLIC"
-//ApacheSoftwareFoundation//DTDTilesConfiguration1.1//EN"
http:
//jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"
tiles-definitions>
definitionname="
member-definition"
path="
/Jsp/layout.jsp"
putname="
top"
/mTop.do"
left"
/mLeft.do"
main"
/defaultMmain.do"
/definition>
/tiles-definitions>
2.在web.xml和struts-config.xml和web.xml中做相应配置:
在struts-config.xml中配置如下:
************
plug-inclassName="
org.apache.struts.tiles.TilesPlugin"
set-propertyproperty="
definitions-config"
/WEB-INF/tiles-defs.xml"
definitions-parser-validate"
value="
true"
/plug-in>
在web.xml中配置如下:
init-param>
param-name>
definitions-config<
/param-name>
param-value>
/WEB-INF/tiles-defs.xml<
/param-value>
/init-param>
*************
3.调用Tiles组件
Tiles组件是通过StrutsAction来调用的,在struts-config.xml中做如下action配置:
action
/member"