Struts初步知识
http://tech.ddvip.com 2008年11月25日 社区交流
Struts初步知识。
此JSP页面不同于普通的JSP页,因为它大量运用了taglib,这些taglib对初学者而言,可能难于掌握,可这却是Struts的精华之一。灵活运用,将大大提高开发效率。
Struts-config.xml:
<Struts-config>
<form-beans>
<form-bean name="regUserForm"
type="org.cjea.Struts.example. RegUserForm "/>
</form-beans>
<action-mappings>
<action path="/regUserAction"
type=" org.cjea.Struts.example.RegUserAction "
attribute=" regUserForm "
scope="request"
validate="false">
<forward name="failure" path="/ messageFailure.jsp"/>
<forward name="success" path="/ messageSuccess.jsp"/>
</action>
</action-mappings>
</Struts-config>
Struts的核心是Controller,即ActionServlet,而ActionServlet的核心就是Struts-config.xml,Struts-config.xml集中了所有页面的导航定义。对于大型的WEB项目,通过此配置文件即可迅速把握其脉络,这不管是对于前期的开发,还是后期的维护或升级都是大有裨益的。掌握Struts-config.xml是掌握Struts的关键所在。
FormBean:RegUserForm
package org.cjea.Struts.example;
import javax.Servlet.http.HttpServletRequest;
import org.apache.Struts.action.ActionForm;
import org.apache.Struts.action.ActionMapping;
public final class RegUserForm extends ActionForm{
private String logname;
private String password;
private String email;
public RegUserForm(){
logname = null;
password = null;
email = null;
}
public String getLogName() {
return this.logname;
}
public void setLogName(String logname) {
this.logname = logname;
}
public void setPassWord(String password) {
this.password = password;
}
public String getPassWord() {
return this.password;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return this.email;
}
public void reset(ActionMapping mapping, HttpServletRequest request)
{
logname = null;
password = null;
email = null;
}
}
责编:豆豆技术应用