⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 struts1.x.txt

📁 Java大部分的基础知识,EJB3,EJB2,WEBSERVICE,SOAP,JMS,MQ,还有些面试题
💻 TXT
📖 第 1 页 / 共 2 页
字号:
第一章、struts简介
	一、struts中的MVC
		M:
			业务、持久
		V:
			jsp
			ActionForm
		C:
			ActionServlet
			RequestProcessor
			ActionMapping
			Action
			ActionForward
		作用:使业务层与界面层强制解藕
	二、处理过程:
		*.do请求表ActionServlet
		ActionServlet转发到RequestProcessor
		RequestProcessor根据url在struts-config.xml中找到ActionForm Action
		RequestProcessor实例化ActionForm并根据类的返射填充ActionForm
		RequestProcessor实例化Action并调用Action的execute方法。
		execute方法执行完后返回一个ActionForward转发到另一个jsp页面。
	三、struts的特点
		struts中的Action中一个单例模式(singlton)
		struts只关心web层的处理,对于业务层及持久层不管。
	四、model2的体系结构
		MVC
			M:javaBean
			V:jsp
			C:servlet
第二章、控制器组件
	一、struts中的MVC
		M:
			业务、持久
		V:
			jsp
			ActionForm
		C:
			ActionServlet
			RequestProcessor
			ActionMapping
			Action
			ActionForward
		作用:使业务层与界面层强制解藕	
	二、RequestProcessor的处理过程
		processPath()	确定选择将要处理的动作的路径
		processMapping()	为请求选择动作映射
			<action path="/login" type="struts.action.LoginAction"
				name="userForm" attribute="userForm"
				scope="session" input="/login.jsp" validate="true"
				>
				<forward name="success" path="/succ.jsp"/>
				<forward name="error" path="/error.jsp"/>
			</action>
		processActionForm()	新建一个 Form Bean 或从请求会话中检索 Form Bean
		processPopulate()	填充与请求关联的 ActionForm
		processForward()	处理 <action-mapping> 元素的 forward 以匹配当前的请求路径
		processValidate()	调用 Form Bean 的 validate() 方法
		processActionCreate()	实例化当前 ActionMapping 指定的类的实例
		processActionPerform()	将调用 action 的 perform() 或 execute() 方法		processPreprocess()	告诉请求处理器调用此方法后是否应继续处理请求
	三、数据源连接
	    <data-sources>
		 <data-source key="Sql"    type="org.apache.commons.dbcp.BasicDataSource">
		   <set-property property="driverClassName"     value="sun.jdbc.odbc.JdbcOdbcDriver" />
		   <set-property property="url"      value="jdbc:odbc:accp" />
		   <set-property property="username" value="" />
		   <set-property property="password" value="" />
		  </data-source>
	    </data-sources>
	  取:
		ServletContext context = servlet.getServletContext();
    		DataSource dataSource =   (DataSource) context.getAttribute("Sql");
		Conneciton con=dataSource.getConnection();
第三章、视图组件
struts的标签库
		<html>
				<html:select property="">
					<html:options/>
				</html:select>
				<html:radio>
				<html:mulitibox value="" property="字符串数组">
			1、错误返回的页面可以保留以前的值。
			2、转发后的form名及范围与前一个form相同,可以直接显示
		<bean> 
			<bean:define name="" id="" scope=""/>			
				从scope中取出name放到变量id中。
			<bean:define id="" scope=""  name=""  property="属性名"/>			
				从scope中取出name的property属性放到变量id中。
			<bean:write name="" property=""/>
				将对象name的值打印。
			<bean:message key=""/>
				通过键名取国际化的值
		<logic>
			<logic:iterator id="" scope="" name="" />
				从scope中取出集合name将其每一个元素放到id中。
			<logic:iterator id="" scope="" name=""  property=""/>
				从scope中取出对象name的property属性值(集合),将其每一个元素放到id中。
			<logic:present name="" scope=""/>
				在scope中是否存在name对象
struts的国际化:不用修改源代码只加入一个properties文件实现国际化
	一、资源文件:名称_语言_国家.properties
			message_en_US.properties
			message_zh_CN.properties
	    如果有非英语或数字,需将资源文件转码native2ascii -encoding utf-8 源  目
	二、在struts-config.xml指定资源文件的名称:包名+文件名(struts.message)
	三、在jsp中通<bean:message key=""/>通过键名加载相关的消息。
struts的校验框架
	手动:所有校验规则要写代码。
	1、国际化两步曲
	2、必须覆盖validate方法
		public class MyForm extends ActionForm
		{
			public ActionErrors validate()
			{
				//如果ActionErrors.size()>=1返回到input页面
				errors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("userName"));
				//new ActionMessage("userName")是键名,保证消息不为空
			}
		}
	3、修改struts-config.xml文件,加入如下信息
		<action
      			attribute="loginForm"
      			input="/login.jsp"
      			name="loginForm"
     			path="/login"
     			scope="request"
     			type="struts.action.LoginAction" validate="true" />
	4、在jsp页面中通过messages标记显示
		<html:messages id="errors">
		<p>
			<bean:write name="errors"/>
		</p>
		</html:messages>
自动:不用写校验代码,通过xml文件说具体的校验规则		
	1、国际化两步曲	
	2、校验通用两步曲
		a、jsp页面显示错误
		b、修改action标签加入validate、input属性	
	3、继承于ValidateForm,因不能覆盖validate方法
		public class MyForm extends ValidateForm
		{
			//public ActionErrors validate()
			//{
			//	如果ActionErrors.size()>=1返回到input页面
			//}
		}
	3、通过配置文件加载两个xml文件
		a、拷入validation-rules.xml,用的struts1.2的。	
		b、将validataion-rules.xml拷贝一份修改如下:
			<formset>
				<form name="loginForm">
					<field property="userName" depends="required">
						<arg0 key="userName"/>				
					</field>
					<field property="pwd" depends="required,minlength">
						<arg0 key="pwd"/>
						<arg1 resource="false" key="${var:minlength}"/>
						<var>
							<var-name>minlength</var-name>
							<var-value>6</var-value>
						</var>
					</field>
				</form>
			</formset>
		c、通过插件加入以上的两个文件
			<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    				<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
  			</plug-in>

action的分类:
	Action只有一个execute方法
	DispatchAction:可以有多个方法	
		public 类  extends DispatchAction
		{
			public void add()
			{}
		}
		<action
      			      attribute="loginForm"
      			      input="/login.jsp"
      			      name="loginForm"
			      path="/login"
			      scope="request"
			      validate="true"
			      type="struts.action.LoginAction" parameter="表单域名" />
tiles:可以定义jsp页面的布局
	tiles的使用:将由多个页面组成的主页面整体布局,是通过
		tiles的一个xml文件来说明,如果页面的结构或具体内容
		发生了改变,只需修改tiles.xml文件,不用改具体的页面代码
		如<jsp:include>。
--做一个action,其转发的结果tiles中的index
	<action path="index" type="struts.action.IndexAction" 
		<forward name="success" path="index"/>
	 </action>
--通过tiles中的index转发到了main.jsp页面
<tiles-definitions>
   <definition name="index" path="/main.jsp">
    <put name="head" value="/head.jsp" />
    <put name="foot" value="/foot.jsp" />
    <put name="body" value="/body.jsp" />
  </definition>
</tiles-definitions>
--main.jsp页面
	<tiles:insert attribute="head"/>
	<tiles:insert attribute="body"/>
	<tiles:insert attribute="foot"/>



	
	
	

	
		
	
一、struts的作用
二、struts的MVC
	m(model):
		facade

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -