网站地图代码b2b网站免费推广
一.纵观本书:
基本原理是实现控制器的功能和展示层的标签.
form+javabean+ActionForm+Action+配置struts-config完成整个的动作,
其中form通过jsp网页的<html:form action="/XXX">的表单参数,提交时,产生XXX.do的动作,这个动作通过,struts-config.xml的配置,找到Action,Action通过ActionForm(这个类跟form的属性名字要全部一样,保证赋值正确性),对里面的值进行初始化,把里面的值赋值给相应的javabean,再JavaBean再去实现一些持久层的操作,再在Action中,通过return mapping.findForward("success");在xml中找到具体的对应的success进行页面的跳转!
里面还有一些小的功能:Validator插件,消息处理和国际化,Tiles框架,Struts应用安全性,对象缓存,分页与排序,文件上传与下载,放置重复提交,过滤器和一些EL,JSTL内容,标签库..
二.xml配置文件:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts-config PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN""http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config><form-beans><form-bean name="UserRegisterForm" type="greatwqs.form.user.UserRegisterForm"/><!--jsp网页里面的form调用,下面没有写Action--></form-beans> <global-exceptions></global-exceptions><global-forwards><forward name="welcome" path="/Welcome.do"/></global-forwards><action-mappings><action path="/ListVideo"type="greatwqs.action.global.ListVideoAction"scope="request"><forward name ="success" path="/ListVideo.jsp"/></action> </action-mappings><controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/><!--Tiles框架之用--><message-resources parameter="greatwqs/error/ApplicationResource"/><!--错误信息配置--><plug-in className="org.apache.struts.tiles.TilesPlugin" ><set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /><set-property property="moduleAware" value="true" /></plug-in> <!-- ===== 验证器========== --><plug-in className="org.apache.struts.validator.ValidatorPlugIn"><set-propertyproperty="pathnames"value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/></plug-in> </struts-config>
三.ActionForm
有与form属性一样的名字的属性:
private String updateemail;
private String updatephone;
和get与set的共有方法;
里面有一个方法继承,进行基本的验证操作,也可以用JS验证和validation.xml验证;
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {ActionErrors actionerrors = new ActionErrors();if(updateemail.equals("")){actionerrors.add("no.updateemail", new ActionMessage("no.updateemail"));//这个要在greatwqs/error/ApplicationResource.properties中制定,错误的信息//在jsp中的<html:errors>显示错误消息}return actionerrors;}
四.Action
里面有一个方法需要继承
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception {//这个里面主要是把form转化到ActionForm的具体类,在赋值给对应的JavaBean//在去结合相应的操作[数据库操作]//最后返回return mapping.findForward("****");这个是到配置文件去找,转发到具体的jsp页面.
}
五.form
主要是应用Struts提供的HTML标签库
如:form,text,password,hidden,submit,cancel,select等,表单标记元素
<html:form action="/search"><html:select property="vary"><html:option value="2">视 频</html:option><html:option value="1">音 乐</html:option></html:select> <html:text property="keyword"/> <html:submit value="NOVA搜索"/>
</html:form>
就写这么多吧,把Struts的基本功能说了,其他的功能就不总结了..