今天有幸接触了一个关于struts1的老项目。要对它进行维护,首先难住我的是关于配置文件。
<form-beans><action-mappings>之类的,上网百度了一下,终于了解了一些,故在此做个记录。
开始:
<form-beans>
<form-bean name="bookForm" type="com.baidu.form.BookForm" />
</form-beans>
用来配置前台发过来的Form传给ActionForm用的,传到后台com.baidu.form.BookForm这个方法会把所有的前台输入的东西拿到。
<action-mappings>
<action path="/createBook" 表示jsp页面form表单中action填写的提交路径
type="com.baidu.action.BookAction" 类型
name="bookForm" action对应的ActionForm
scope="request" 作用范围,request表示只作用与请求
input="/CreateBook.jsp" 输入页面。
</action>
<forward name="failure" path="/CreateBook.jsp"/> forward 表示跳转 当你返回的值是failure就调转到CreatBook.jsp页面。。。。下同
<forward name="cancel" path="/index.jsp"/>
</action-mappings>
这里的name和form-bean里面的name得是一样的。
关于<bean:message>的问题???
<bean:message key="pageingDisplay.title"></bean:message>这句话是什么意思啊???
输出一条信息,这个信息来源于配置文件*.properties文件
文件内容由下: pageingDisplay.title=标题
<bean:message key="pageingDisplay.title"></bean:message>输出:标题
关于<bean:write>的问题???
使用<bean:write name="editEntryFormBean" property="warning" />
在editEntryFormBean(这是一个Form)里面必须要有getWarning()和setWarning()方法。但是,属性名称可以随便!什么意思呢?例如:
private String message;
public void setWarning(String message)
{ this.message = message; }
public String getWarning()
{ return this.message; }
依然可以的!
但是我不建议这么做!最好还是起一样的属性名称warning,看着也舒心。你觉得呢?
关于<bean:define>的问题???
<bean:define>标签用于定义一个变量.id属性指定变量的名字,toScope属性指定变量存放范围,如果没有设置toScope属性,则变量存放在page范围内.
同时设定name和property属性.name属性指定一个已经存在的bean,property属性指定已经存在的bean中的某个属性,id属性定义的变量值由property属性决定:
<%request.setAttribute("sessionBean",session);%>
<bean:define id="contextBean" name="sessionBean" property="servletContext"/>
Servlet Context name:<bean:write name="contextBean" property="servletContextName"/>