phrash1 2012-5-9 start------------------
1.配置Struts步骤:1.将现有项目中的struts.xml拷贝到src包下;2.将struts用到的.jar文件拷贝到lib包
下;3.配置web.xml,拷贝filter的两段配置即<filter>...</filter> 和<filter-mapping>...</filter-mapping>
2.ng即next generation,struts2.0用的filter为dispatcherfilter;struts2.1用的filter为
strutsprepareandexecutefilter.
3.struts.xml下添加<package ...>...</package>里的action等,struts.xml中的package类似于j2se中的
package,package中result默认为name="success"
4.查看源代码(或javadoc)配置,在reference libraries右键--properties--java attachment--location path
5.xml语法提示设置:window-preference-type filter text输入xml-xml catalog--add..--struts-dtd
jsp中文配置:window-preference-jsp-encoding选择Chinese National Standard
6.struts是将请求与视图分离;执行过程为:url--http--tomcat--webapp--web.xml--filter--struts.xml--
namespace--action--result ,namespace决定了action的访问路径,默认为"",可接收所有路径的
action,namespace 可以写成/或/xxx或/xxx/yyy,对应的action访问路径为/index.action
或/xxx/index.action或/xxx/yyy/index.action,namespace 最好以模块来进行命名
7.设计模式好处:灵活性,易扩展
8.在myeclipse中拷贝web项目时访问不生效,可能是新项目右键preference--myeclipse--web--web
context root没有变成最新的项目名称。另引入已有项目时可能JRE版本路径会有不一样,可以先删
除再导入现在的JRE
9.具体视图action的返回可以用户通过class来指定,如<action name="index" class="xxx1">或<action
name="index" class="xxx2">,类xxx1或xxx2中只要有execute()方法且其返回值为String时,此类就
被struts认为是一个action。struts1只new一次,以后每次访问都为同一个class,会有同步问题;而
struts2每访问一次就new一个class。如果没有配置class则默认调用ActionSupport类(此类在xwork-
2.1.2.jar包中)中的execute()方法。xxx1类还可以实现Action接口或继承ActionSupport类,开发中使用
最后一种方式即继承ActionSupport类,前两种都用不了ActionSupport类中的其他方法。
10.访问路径问题:basePath 默认jsp文件会设置好,可以在<head>中添加<base href="<%
=basePath%>"/>,就能处理页面跳转路径问题,redirect也可以,但可以忽略。统一使用绝对路径(在
jsp中用request.getContextRoot方法得到webapp路径或使用myeclipse常用的指定basePath),struts中
路径是根据action的路径而不是jsp路径来确定的,所以尽量不使用相对路径。
phrash1 2012-5-9 end------------------