struts中的logic:present标签 用于实现分页功能

struts1 table标签中Logic的使用属性 这个里面讲解了有关Logic的所有使用方法,例如empty和iterator的应用 立即下载
 

在action中:

request.getSession().setAttribute("pageBean", pageBean);

request.setAttribute("result", pageBean.getObjList());

 

在jsp中:
<logic:present >
       <logic:iterate >
            <logic:present >
                <tr>
                    <td><bean:write property="name" /></td>
                    <td><bean:write property="author" /></td>
                    <td><bean:write property="price" /></td>
                 </tr>
             </logic:present>
        </logic:iterate>
</logic:present>

<logic:present scope="session">这里有个scope属性可能是request,session等,name指的是一个对象,可能是 javaBean,也可能是集合的对象,整个意思就是就是在scope(session,request)范围里面查找name(一个对象)是否存在,相 当于一个if()语句.

 

 

本章讲解了一个简单的Struts应用例子helloapp应用,这个例子可以 帮助读者迅速入门,获得开发Struts应用的基本经验。该应用的功能非常简单,接受用户输入的姓名<name>,然后输出“Hello <name>”。开发helloapp应用涉及以下内容:

l         分析应用需求

l         把基于MVC设计模式的Struts框架运用到应用中

l         创建视图组件,包括HTML表单(hello.jsp)和ActionForm Bean(HelloForm.java)

l         创建application.properties资源文件

l         数据验证,包括表单验证和业务逻辑验证

l         创建控制器组件: HelloAction.java

l         创建模型组件: PersonBean.java

l         创建包含被各个模块共享的常量数据的Java文件: Constants.java

l         创建配置文件:web.xml和struts-config.xml

l         编译、发布和运行helloapp应用

2.1 分析helloapp应用的需求
在开发应用时,首先从分析需求入手,列举该应用的各种功能,以及限制条件。helloapp应用的需求非常简单,包括如下需求:

l         接受用户输入的姓名<name>,然后返回字符串“Hello <name> !”

l         如果用户没有输入姓名就提交表单,将返回出错信息,提示用户首先输入姓名。

l         如果用户输入姓名为“Monster”,将返回出错信息,拒绝向“Monster”打招呼。

l         为了演示模型组件的功能,本应用使用模型组件来保存用户输入的姓名。

2.2 运用Struts框架
下面把Struts框架运用到helloapp应用中。Struts框架可以方便迅速的把一个复杂的应用划分成模型、视图和控制器组件,而Struts的配置文件struts-config.xml则可以灵活的组装这些组件,简化开发过程。

以下是helloapp应用的各个模块的构成:

l         模型包括一个JavaBean组件PersonBean,它有一个userName属性,代表用户输入的名字。它提供了get/set方法,分别用于读取 和设置userName属性,它还提供一个save()方法,负责把userName属性保存到持久化存储系统中,如数据库或文件系统。对于更为复杂的 Web应用,JavaBean组件可以作为EJB或Web服务的前端组件。

l         视图包括一个JSP文件hello.jsp,它提供用户界面,接受用户输入的姓名。视图还包括一个ActionForm Bean,它用来存放表单数据,并进行表单验证,如果用户没有输入姓名就提交表单,将返回出错信息。

l         控制器包括一个Action类HelloAction,它完成三项任务:1.进行业务逻辑验证,如果用户输入的姓名为“Monster”, 将返回错误消息;2.调用模型组件PersonBean的save()方法,保存用户输入的名字;3.决定将合适的视图组件返回给用户。

 

除了创建模型、视图和控制器组件,还需要创建Struts的配置文件struts-config.xml,它可以把这些组件组装起来,使它们协调工作。此外,还需要创建整个Web应用的配置文件web.xml。

2.3 创建视图组件
本例中,视图包括两个组件:

l         一个JSP文件:hello.jsp

l         一个ActionForm Bean: HelloForm Bean

 

下面分别讲述如何创建这两个组件。

2.3.1 创建JSP文件
hello.jsp提供用户界面,能够接受用户输入的姓名。此外,本Web应用的所有输出结果也都由hello.jsp显示给用户。图2-1显示了hello.jsp提供的网页。


图2-1 hello.jsp的网页

在图2-1中,用户输入姓名“Weiqin”后,按提交表单,本应用将返回“Hello Weiqin!”,参见图2-2。


图2-2 hello.jsp接受用户输入后正常返回的网页

 

例程2-1为hello.jsp文件的源代码。

例程2-1 hello.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ 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" %>

 

<html:html locale="true">

<head>

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

    <html:base/>

</head>

 

<body bgcolor="white"><p>

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

   <html:errors/><p>                    

 

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

       <h2>

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

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

       </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>

 

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

</body>

</html:html>

以上基于Struts框架的JSP文件有以下特点:

l         没有任何Java程序代码

l         使用了许多Struts的客户化标签,例如<html:form>和<logic:present>标签

l         没有直接提供文本内容,取而代之的是<bean:message>标签,输出到网页上的文本内容都是由<bean:message>标签来生成的。例如:

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

 

Struts客户化标签是联系视图组件和Struts框架中其它组件的纽带。这些标签可以访问或显示来自于控制器和模型组件的数据。在本书第12章至16章讲专门介绍Struts标签的用法,本节先简单介绍几种重要的Struts标签。

 

hello.jsp开头几行用于声明和加载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" %>

 

以上代码表明该JSP文件使用了Struts Bean、Html和Logic 标签库,这是加载客户化标签库的标准JSP语法。

hello.jsp中使用了来自 Struts HTML标签库中的标签,包括<html:errors>, <html:form>和<html:text>:

l         <html:errors>:用于显示Struts框架中其他组件产生的错误消息。

l         <html:form>:用于创建HTML表单,它能够把HTML表单的字段和ActionForm Bean的属性关联起来。

l         <html:text>:该标签是<html:form>的子标签,用于创建HTML表单的文本框。它和ActionForm Bean的属性相关联。

 

hello.jsp中使用了来自Struts Bean标签库的两个标签<bean:message>和<bean:write> :

l         <bean:message>:用于输出本地化的文本内容,它的key属性指定消息key,和消息key匹配的文本内容来自于专门的 Resource Bundle,关于Resource Bundle的概念参见本书第9章(Struts应用的国际化)。

l         <bean:write>:用于输出JavaBean的属性值。本例中,它用于输出personbean对象的userName属性值:

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

 

hello.jsp使用了来自Struts Logic标签库的<logic:present>标签。<logic:present>标签用来判断JavaBean在特定的范围内是否存在,只有当JavaBean存在,才会执行标签主体中的内容:

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

       <h2>

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

       </h2>

</logic:present>

本例中,<logic:present>标签用来判断在request范围内是否存在personbean对象,如果存在,就输出 personbean的userName属性值。和<logic:present>标签相对的 是<logic:notPresent>标签,它表示只有当JavaBean在特定的范围内不存在,才会执行标签主体中的内容。

2.3.2 创建消息资源文件
hello.jsp使用<bean:message>标签来输出文本内容。这些文本来自于Resource Bundle,每个Resource Bundle都对应一个或多个本地化的消息资源文件,本例中的资源文件为application.properties,例程2-2是该消息资源文件的内 容。

例程 2-2 application.properties文件

#Application Resources for the "Hello" sample application

hello.jsp.title=Hello - A first Struts program

hello.jsp.page.heading=Hello World! A first Struts application

hello.jsp.prompt.person=Please enter a UserName to say hello to :

hello.jsp.page.hello=Hello

 

#Validation and error messages for HelloForm.java and HelloAction.java

hello.dont.talk.to.monster=We don't want to say hello to Monster!!!

hello.no.username.error=Please enter a <i>UserName</i> to say hello to!

以上文件以“消息key/消息文本”的格式存放数据,文件中“#”后面为注释行。对于以下JSP代码:

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

<bean:message>标签的key属性为“hello.jsp.tilte”,在Resource Bundle中与之匹配的内容为:

hello.jsp.title=Hello - A first Struts program

因此,以上<bean:message>标签将把“Hello - A first Struts program”输出到网页上。

2.3.3 创建ActionForm Bean
当用户提交了HTML表单,Struts框架自动把表单数据组装到ActionForm Bean中。ActionForm Bean中的属性和HTML表单中的字段一一对应。ActionForm Bean还提供数据验证方法,以及把属性重新设置为默认值的方法。Struts框架中定义的ActionForm类是抽象的,必须在应用中创建它的子类, 来存放具体的HTML表单数据。例程2-3为HelloForm.java的源程序, 它用于处理hello.jsp中的表单数据。

例程2-3 HelloForm.java

package hello;

 

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMessage;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

 

public final class HelloForm extends ActionForm {

 

    private String userName = null;

 

    public String getUserName() {

        return (this.userName);

    }

 

    public void setUserName(String userName) {

        this.userName = userName;

    }

 

    /**

     * Reset all properties to their default values.

     */

    public void reset(ActionMapping mapping, HttpServletRequest request) {

        this.userName = null;

    }

 

    /**

     * Validate the properties posted in this request. If validation errors are

     * found, return an <code>ActionErrors</code> object containing the errors.

     * If no validation errors occur, return <code>null</code> or an empty

     * <code>ActionErrors</code> object.

     */

    public ActionErrors validate(ActionMapping mapping,

                                 HttpServletRequest request) {

 

        ActionErrors errors = new ActionErrors();

 

        if ((userName == null) || (userName.length() < 1))

            errors.add("username", new ActionMessage("hello.no.username.error"));

 

        return errors;

    }

}

从以上代码可以看出,ActionForm Bean实质上是一种JavaBean,不过它除了具有JavaBean的常规方法,还有两个特殊方法:

l         validate():用于表单验证。

l         reset():把属性重新设置为默认值。

2.3.4 数据验证
几乎所有和用户交互的应用都需要数据验证,而从头设计并开发完善的数据验证机制往往很费时。幸运的是,Struts框架提供了现成的、易于使用的数据验证功能。Struts框架的数据验证可分为两种类型:表单验证和业务逻辑验证,在本例中,它们分别运用于以下场合:

l         表单验证:如果用户没有在表单中输入姓名,就提交表单,将生成表单验证错误

l         业务逻辑验证:如果用户在表单中输入的姓名为“Monster”,按照本应用的业务规则,不允许向“Monster”打招呼,因此将生成业务逻辑错误。

 

第一种类型的验证,即表单验证由ActionForm Bean来负责处理。在本例中,HelloForm.java的validate()方法负责完成这一任务:

public ActionErrors validate(ActionMapping mapping,

                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();

 

        if ((userName == null) || (userName.length() < 1))

            errors.add("username", new ActionMessage("hello.no.username.error"));

 

        return errors;

    }

}

当用户提交了HTML表单,Struts框架自动把表单数据组装到ActionForm Bean中。接下来Struts框架会自动调用ActionForm Bean的validate()方法进行表单验证。如果validate()方法返回的ActionErrors 对象为null,或者不包含任何ActionMessage对象,就表示没有错误,数据验证通过。如果ActionErrors中包含 ActionMessage对象,就表示发生了验证错误,Struts框架会把ActionErrors对象保存到request范围内,然后把请求转发 到恰当的视图组件,视图组件通过<html:errors>标签把request范围内的ActionErrors对象中包含的错误消息显示 出来,提示用户修改错误。

 


在Struts早期的版本中,使用ActionError类来表示错误消息,ActionError类是ActionMessage的子类。Struts1.2将废弃ActionError,统一采用ActionMessage类来表示正常或错误消息。


第二种类型的验证,即业务逻辑验证,由Action来负责处理,参见本章2.4.3节。

2.4 创建控制器组件
控制器组件包括ActionServlet类和Action类。ActionServlet类是Struts框架自带的,它是整个Struts框架的控制 枢纽,通常不需要扩展。Struts框架提供了可供扩展的Action类,它用来处理特定的HTTP请求,例程2-4为HelloAction类的源程 序。

例程2-4 HelloAction.java

package hello;

 

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpSession;

import javax.servlet.http.HttpServletResponse;

 

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionMessage;

import org.apache.struts.action.ActionMessages;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.util.MessageResources;

 

public final class HelloAction extends Action {

 

    /**

     * Process the specified HTTP request, and create the corresponding HTTP

     * response (or forward to another web component that will create it).

     * Return an <code>ActionForward</code> instance describing where and how

     * control should be forwarded, or <code>null</code> if the response has

     * already been completed.

     */

    public ActionForward execute(ActionMapping mapping,

                                 ActionForm form,

                                 HttpServletRequest request,

                                 HttpServletResponse response)

    throws Exception {

 

        // These "messages" come from the ApplicationResources.properties file

        MessageResources messages = getResources(request);

 

        /*

         * Validate the request parameters specified by the user

         * Note: Basic field validation done in HelloForm.java

         *       Business logic validation done in HelloAction.java

         */

        ActionMessages errors = new ActionMessages();

        String userName = (String)((HelloForm) form).getUserName();

 

        String badUserName = "Monster";

 

        if (userName.equalsIgnoreCase(badUserName)) {

           errors.add("username", new ActionMessage("hello.dont.talk.to.monster",

badUserName ));

           saveErrors(request, errors);

           return (new ActionForward(mapping.getInput()));

        }

 

        /*

         * Having received and validated the data submitted

         * from the View, we now update the model

         */

        PersonBean pb = new PersonBean();

        pb.setUserName(userName);

        pb.saveToPersistentStore();

 

        /*

         * If there was a choice of View components that depended on the model

         * (or some other) status, we'd make the decision here as to which

         * to display. In this case, there is only one View component.

         *

         * We pass data to the View components by setting them as attributes

         * in the page, request, session or servlet context. In this case, the

         * most appropriate scoping is the "request" context since the data

         * will not be neaded after the View is generated.

         *

         * Constants.PERSON_KEY provides a key accessible by both the

         * Controller component (i.e. this class) and the View component

         * (i.e. the jsp file we forward to).

         */

 

        request.setAttribute( Constants.PERSON_KEY, pb);

 

        // Remove the Form Bean - don't need to carry values forward

        request.removeAttribute(mapping.getAttribute());

 

        // Forward control to the specified success URI

        return (mapping.findForward("SayHello"));

    }

}

 

HelloAction.java是本应用中最复杂的程序,下面分步讲解它的工作机制和流程。

2.4.1 Action类的工作机制
所有的Action类都是org.apache.struts.action.Action的子类。Action子类应该覆盖父类的execute() 方法。当ActionForm Bean被创建,并且表单验证顺利通过后, Struts框架就会调用Action类的execute()方法。execute()方法的定义如下:

 

public ActionForward execute(ActionMapping mapping,

                  ActionForm form,

                  HttpServletRequest request,

                  HttpServletResponse response) throws IOException, ServletException ;

 

execute()方法包含以下参数:

l         ActionMapping:包含了这个Action的配置信息,和struts-config.xml文件中的<action>元素对应。

l         ActionForm:包含了用户的表单数据,当Struts框架调用execute()方法时,ActionForm中的数据已经通过了表单验证。

l         HttpServletRequest:当前的HTTP请求对象

l         HttpServletResponse:当前的HTTP响应对象

 

Action类的execute()方法返回ActionForward对象,它包含了请求转发路径信息。

2.4.2 访问封装在MessageResources中的本地化文本
在本例中,Action类的execute()方法首先获得MessageResources对象:

MessageResources messages = getResources(request);

 

在Action类中定义了getResources(HttpServletRequest request)方法,该方法返回当前默认的MessageResources对象,它封装了Resource Bundle中的文本内容。接下来Action类就可以通过MessageResources对象来访问文本内容。例如,如果要读取消息key为 “hello.jsp.title”对应的文本内容,可以调用MessageResources类的getMessage(String key)方法:

String title=messages.getMessage("hello.jsp.title");

2.4.3 业务逻辑验证
接下来,Action类的execute()方法执行业务逻辑验证:

ActionMessages errors = new ActionMessages();

String userName = (String)((HelloForm) form).getUserName();

 

String badUserName = "Monster";

 

if (userName.equalsIgnoreCase(badUserName)) {

   errors.add("username", new ActionMessage("hello.dont.talk.to.monster", badUserName ));

   saveErrors(request, errors);

   return (new ActionForward(mapping.getInput()));

}

如果用户输入的姓名为“Monster”,将创建包含错误信息的ActionMessage对象,ActionMessage对象被保存到 ActionMessages对象中。接下来调用在Action基类中定义的saveErrors()方法,它负责把ActionMessages对象保 存到request范围内。最后返回ActionForward对象,Struts框架会根据ActionForward对象包含的转发信息把请求转发到 恰当的视图组件,视图组件通过<html:errors>标签把request范围内的ActionMessages对象中包含的错误消息显 示出来,提示用户修改错误。

在2.3.4节还提到了ActionErrors对象,图2-3显示了ActionMessages、ActionErrors、 ActionMessage和ActionError类的类框图。ActionErrors继承ActionMessages,ActionError继 承ActionMessage,ActionMessages和ActionMessage之间为聚集关系,即一个ActionMessages对象中可 以包含多个ActionMessage对象。

 


图2-3 ActionMessages、ActionErrors、ActionMessage和ActionError类的类框图

表单验证通常只对用户输入的数据进行简单的语法和格式检查,而业务逻辑验证会对数据进行更为复杂的验证,很多情况下,需要模型组件的介入,才能完成业务逻辑验证。

struts1中的logic标签用法 精通struts1的logic标签的使用方法,比传统的web jsp技术更能节省代码开销,提高系统的运行效率 立即下载

相关推荐

从单应矩阵到实际距离:Apriltag测距完整实现指南

本文提供了基于Apriltag实现高精度视觉测距与姿态估计的完整指南。详细阐述了从相机标定、单应矩阵分解到欧拉角与距离计算的完整流程,并深入探讨了四个解的歧义选择、工程实践中的滤波优化与多Tag融合等关键问题,旨在帮助开发者在机器人、AR等应用中实现稳定可靠的距离检测与姿态估计。

n7o8p的博客 563

Struts标签logic:present

如果指定的值出现该标签就会创建其标签体内的内容。该标签用于以下情况: 检查具有指定名称的cookie是否出现。  检查具有指定名称的header是否出现。  检查具有指定名称的JSP Bean是否出现 或 检查具有指定名称的JSP Bean中的property属性是否出现。  检查request中指定名称的参数是否出现。  检查当前的认证用户是否与指定的安全角色相关联。  检查当前认证的主体是否具

u013681658的博客 1111

ChipCamp探索系列 -- 7A. 开源CPU之BOOM的来龙去脉

本文梳理一下Berkeley的乱序超标量CPU项目----Berkeley Out of Order Machine (BOOM),作为探索7系的首篇(7A)。

ChipCamp的博客---https://chipcamp.blog.csdn.net/ 1566

<logic:present>理解

--------present英文意思有呈现的意思。 如上代码:从session范围内取出name为result的对象呈现。 表示将要对name为result的对象开始迭代,并将对象别名为book。 将名称为book这个对象实例开始呈现。 写出book(大部分是ActionForm)对象实例的price

新一难的博客 8449

GEE影像重采样实战:从10米到500米,如何用.reduceResolution和.reproject统一尺度?

本文详细介绍了在Google Earth Engine (GEE)平台中,如何利用`.reduceResolution()`和`.reproject()`方法解决多源遥感影像的尺度统一难题。通过实战案例,从哨兵2号10米分辨率影像聚合至MODIS 500米尺度,阐述了聚合规则选择、参数配置及效果验证的全流程,为环境监测、农业分析等领域的跨尺度数据融合提供了关键方法。

weixin_29223603的博客 91

SAP BW/4HANA 项目字段级数据血缘分析的方法与工具

利用SAP自带工具可以在一定程度上查看数据流和字段使用情况,但往往需要人工逐步深挖。适用于简单场景或验证单个字段的映射。借助SAP数据治理解决方案(如 Information Steward、Data Intelligence 等)能够自动整合元数据,提供图形化、跨系统的血缘分析,适合对数据 lineage 有严格要求的企业级项目。第三方工具则提供了灵活强大的功能,如自动文档、生成功能丰富的报告,对于复杂环境下的血缘分析和影响分析非常有帮助。自行开发SQL/CDS脚本。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 481

logic:present

logic:present 标签只是用来判断在某一个作用域范围内是否存在着某一个变量, 例如: <logic:present name="message" scope="request"> 在request作用域范围内存在message变量 </logic:present> <logic:notPresent name=...

weixin_30315905的博客 237

PCL 加权局部最优投影(WLOP)简化算法

WLOP算法是一种点云重采样方法,通过迭代优化实现点云均匀化和特征保留。算法包含数据项(加权平均位置保持几何特征)和正则化项(排斥邻近点实现均匀分布)两部分。代码实现基于PCL库,通过KD树加速邻域搜索,使用高斯权重函数计算点位置更新。参数包括输出点比例、邻域半径、正则化权重和迭代次数。该算法不依赖网格信息,适合处理大规模扫描数据的预处理优化。

点云侠的博客 650

logic:present 和 logic:empty的用法

 logic:present 和 logic:empty他们的用法大致相同,唯一的不同点是:两者在对空字符串的处理上存在着不同。下面为index.jsp中的代码: 1 2 notpresent 3 4 5 notempty 6 7 8 empty 9 10 11 present12 当第一次访问该JSP的时候,由

swandragon的专栏 2379

OpenClaw Docker 安装与部署教程,环境隔离不冲突技术指南

本文介绍了使用Docker容器化部署OpenClaw的完整教程。首先通过流程图详细说明了Docker环境检测流程,包括系统支持性检查、Docker安装状态验证、版本检测和服务配置等步骤。然后提供了Windows、macOS和Linux(Ubuntu/CentOS)系统下的Docker安装指南,涵盖从下载、安装到权限配置的全过程。最后介绍了OpenClaw官方镜像的拉取方法以及自定义镜像构建的Dockerfile示例。该教程适用于开发和生产环境,利用Docker实现环境隔离和快速部署。

一键难忘的博客 998

渗透测试面试题

渗透测试面试题 一.思路流程 1.信息收集 服务器的相关信息(真实ip,系统类型,版本,开放端口,WAF等) 网站指纹识别(包括,cms,cdn,证书等),dns记录 whois信息,姓名,备案,邮箱,电话反查(邮箱丢社工库,社工准备等) 子域名收集,旁站,C段等 google hacking针对化搜索,pdf文件,中间件版本,弱口令扫描等 扫描网站目录结构,爆后台,网站banner,测试文件,...

千寻的博客 12万+

struts中的logic:present标签 用于实现分页功能(转)

<br />在action中:<br />request.getSession().setAttribute("pageBean", pageBean);<br />request.setAttribute("result", pageBean.getObjList());<br />在jsp中:<br /><logic:present ><br />       <logic:iterate ><br />            <logic:present ><br />               

liuxilil的专栏 1346

QCC305x-QCC304x系列开发教程之应用程序子系统详解 嵌入式

本文对QCC305x-QCC304x系列芯片的应用程序子系统进行了详细解析,并给出了一个LED闪烁的示例代码。嵌入式系统的开发既需要理论知识的支持,也需要实践经验的积累,希望本文能够为读者在QCC305x-QCC304x系列芯片的开发中提供一些有益的指导。QCC305x-QCC304x系列芯片提供了丰富的外设接口,包括UART、SPI、I2C等,开发者可以根据需求选择适合的接口进行数据传输和控制。QCC305x-QCC304x系列芯片的应用程序子系统是整个嵌入式系统的核心部分,负责管理和执行各种应用程序。

CodeMaven的博客 227

struts的logic:empty,logic:notEmpty,logic:iterate,bean:write标签

1. logic:empty标签判断脚本变量是否为null,是否是一个空的字符串(长度为0),是否是一个空的collection或map(调用isEmpty()方法来判断)。logic:notEmpty判断标签不为空时处理标签。 <logic:empty name="myBean"> 是空的 </logic:empty> <logic:notEmpty name="m...

这四个杀手的博客 678

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

struts标签之logic手册

logic:iterate logic:iterate标签用来迭代集合,您可以使用如下方式来为这个标签指定其要叠代的集合:使用一个运行时表达式,这个表达式的值是一个集合。 用name属性引用一个JSP Bean,这个JSP Bean本身就是一个集合。 用name属性引用一个JSP Bean,这个JSP Bean的一个属性是一个集合,这时可以联合使用property来指定这个集合。 上面所提到的集合

kevin781128的专栏 240

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Struts_logic标签 之一 empty , notempty ,present ,notpresent

用于判断数据是否为空是否存在. show.jsp struts_logic 测试 empty , notempty ,present ,notpresent 相当于 if logic:empty判断为空不为空 att0为空! att0为不空!

my Code 1747

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

logic:empty和logic:notEmpty的用法和区别

logic:empty标签判断脚本变量是否为null,是否是一个空的字符串(长度为0),是否是一个空的collection或map(调用isEmpty()方法来判断)。logic:notEmpty判断标签不为空时处理标签。 是空的 不为空 上段代码表示当一个名为myBean的bean在所有的scope中都不存在时,输出The bean is m...

学会坚强 3159

struts框架bean,html,logic标签手册

(转自solol.org)目录:bean:cookiebean:define bean:header bean:include bean:message bean:page bean:parameter bean:resource bean:size bean:struts bean:write html:base html:cancel html:select html:checkbox htm

xiaosaq的专栏 797

struts标签库:logic:empty logic:notPresent 界面

index.jsp 测试logic:empty,logic:notEmpty,logic:present,logic:notPresent标签 empty_present.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"

1946

struts标签bean:cookie,bean:write,logic:page,logic:present,logic:iterate使用实例

jsp页面index.jsp:%@page contentType="text/html;charset=gb2312" language="java"%>%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>%@taglib uri

lanbosan的专栏 1386

struts标签-------logic

 logic:iteratelogic:iterate标签用来迭代集合,您可以使用如下方式来为这个标签指定其要叠代的集合: 使用一个运行时表达式,这个表达式的值是一个集合。 用name属性引用一个JSP Bean,这个JSP Bean本身就是一个集合。 用name属性引用一个JSP Bean,这个JSP Bean的一个属性是一个集合,这时可以联合使用p

懒散狂徒的专栏 1778

logic标签的equal,logic:present用法

logic:equal,logic:present用法 1. &lt;logic:equal value="a" name="documentContent"&gt;显示&lt;/logic:equal&gt;   &lt;logic:equal name="DeliverProveForm" property="userAction" value="create&qu

pan_junbiao的博客 9898

bean:define、logic:present、logic:empty使用总结

bean:define用来吧中的值定义到java变量中 logic:present判断bean是否存在,判断地址 logic:empty判断bean的属性值是否为null

平常心的小屋 534
上一篇: Oracle 字段类型
下一篇: Oracle基础入门
kele1121
博客等级 码龄20年 5粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值