| 3.3 forms and formbean interactions |
|
note: 这里给出的例子使用了jsp 和custom tags, the actionform beans 和其他的struts controller组件 是独立于view的。struts可以和velocity templates, xlst, 以及其他任何presentation technology that can be rendered via a java servlet一同使用。参见resources page 。 曾经,大多数web开发者使用html的标准方式构建forms ,如<input> tag。用户们期望交互式的应用程序拥有某些行为,这些期望中的一个涉及到了错误处理 – 如果用户产生了一个错误,应用程序应该允许他们修正错误而不必要重新键入form中的其他正确信息。 使用标准的html和jsp页面实现这种功能是单调而又麻烦的。例如,一个username的input元素可能会是这样: <input type="text" name="username" value="<%= loginbean.getusername() %>"/> 这个键入起来困难,并且没有编程基础的html开发者看到这个会很困惑,并且给html编辑器带来问题。相反,struts 提供了一个基于jsp1.1 custom tag基础上的构建forms的全面的方案。上面的例子如果使用struts将会是这样: <html:text property="username"/>
不必显式的给text框赋初值。jsp tag将自动为你做这些事情。 |
