struts in my eye1

struts

 

本文主要针对struts的初级学者进行,依据简单的say hello 程序对struts进行探讨。

注释:为红色内容

 

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

(用到的struts标签库要事先声明)

<html:html locale="true">(英文解释:Should we set the current Locale for this user if needed?翻译:如果需要的情况下,我们为用户设置当前位置。具体什么意思先待定)

  <head>

<title><bean:message key="hello.jsp.title"/></title>

(查找application.properties文件找到hello.jsp.title的对应值,显示)

    <html:base/>

  </head>

  <body bgcolor="white"><p>

 

    <h2><bean:message key="hello.jsp.page.heading"/></h2><p>

(查找application.properties文件找到hello.jsp.page.heading的对应值,显示)

 

   <html:errors/><p>

 

<logic:present name="personbean" scope="request">

(如果该Bean存在的话,显示如果不存在则不显示)

       <h2>

         <bean:message key="hello.jsp.page.hello"/>

(查找resource Boudle找到hello.jsp.page.hello的对应值,显示)

         <bean:write name="personbean" property="userName" />!<p>

(输出personbeanuserName属性)

       </h2>

    </logic:present>

 

    <html:form action="/HelloWorld.do" focus="userName" >

 

      <bean:message key="hello.jsp.prompt.person"/>

      <html:text property="userName" size="16" maxlength="16"/><br>

 

      <html:submit property="submit" value="Submit"/>

      <html:reset/>

 

    </html:form><br>

(用户提交表单之后,struts把该信息组装到ActionForm Bean中。然后struts调用Action Form Beanvaludate()方法进行表单验证。如果返回值为NULL则表示验证通过;如果验证错误就是说ActionErrors中包含ActionMessage对象,struts就会把该对象保存到request范围内,然后把请求转发到适当的视图组件,视图组件通过<htmlerrors>标签把request范围内的ActionErrors对象中包含的错误信息显示出来

    <html:img page="/struts-power.gif" alt="Powered by Struts"/>

 

  </body>

</html:html>

 

form的执行:

 

定义:FormAction &&Action&&Message

表单验证的时候先调用FormAction,再调用Action的相关方法。

FormAction.validate(),再调用Action.execute

你可能感兴趣的:(html,bean,jsp,Web,struts)