Struts2第三篇【Action开发方式、通配符、Struts常量、跳转全局视图、action节点默认配置】...

前言

上篇Struts博文已经讲解了Struts的开发步骤以及执行流程了…..对Struts的配置文件有了了解…..本博文继续讲解Struts在配置的时候一些值得要学习的细节…

Action开发的三种方式

在第一次我们写开发步骤的时候,我们写的Action是继承着ActionSupport类的…为啥我们继承了ActionSupport类呢?下面我就会讲解到

继承ActionSupport类

我们来看一下ActionSupport干了什么:

这里写图片描述

也就是说,如果我们在Action类中需要用到Struts为我们提供的数据校验等Struts已经帮我们实现的功能,我们就继承着ActionSupport类..


实现Action接口

我们再来看看Action接口干了什么:

这里写图片描述

当然啦,ActionSuppot也继承着Action接口,所以ActionSuppot拥有Action接口的全部功能….因此,这种开发方式我们是比较少用的…


不继承任何类、不实现任何接口

开发此类的Action,它是不继承任何类、不实现任何接口的…也就是说,它就是一个普通的Java类….

  • Action类

public class PrivilegeAction  {


    public String login() {
        System.out.println("我是普通的javaAction,不继承任何的类、不实现任何的接口");

        return "success";
    }
}
  • 在配置文件中配置:

<struts>
<package name="privilige" extends="struts-default">
    <action name="login" class="privilegeaction.PrivilegeAction" method="login">
        <result name="success">/index.jsp</result>
    </action>
</package>
</struts>
  • 效果:

这里写图片描述


小总结

一般我们开发Action都是直接继承着ActionSupport类的…….


通配符

为什么要学习通配符

在讲解通配符之前,我们来看一下需求…..

现在我的Action中有两个方法,处理登陆和处理注册:


public class PrivilegeAction extends ActionSupport {

    public String login() {
        System.out.println("我是登陆");

        return "success";
    }

    public String register() {
        System.out.println("我是注册");
        return "success";
    }
}

因此,我们就需要在struts.xml文件中配置两个action节点



    <action name="login" class="privilegeaction.PrivilegeAction" method="login">
        <result name="success">/index.jsp</result>
    </action>

    <action name="register" class="privilegeaction.PrivilegeAction" method="register">
        <result name="success">/index.jsp</result>
    </action>

现在我们发现:它们仅仅只有访问路径和方法的名称是不一样的….但是这却要多配置一个action节点,会造成浪费!

于是乎通配符就应运而生了…


使用通配符改造

没有通配符之前,我们是需要配置两个action的…有了通配符,我们是这样做的:


<package name="privilige" extends="struts-default">

    <action name="privilege_*" class="privilegeaction.PrivilegeAction" method="{1}">
        <result name="success">/index.jsp</result>
    </action>

</package>

解释一下:

  • name=privilege_*,我们用了_作为分隔符。*就是我们的通配符
  • {1},就是代表着第一个通配符

我们来看一下效果:

这里写图片描述

同理可得,当我们在地址栏访问login的时候,就会执行login的方法

这里写图片描述


Struts中路径的匹配原则

有的时候,我们可能会在package节点中指定namespace名称空间,我们在访问对应的资源名称的时候,就需要在前面加入相对应名称空间的值…

比如:

名称空间的值为“/user”

<package name="privilige" extends="struts-default" namespace="/user">
    <action name="privilege_*" class="privilegeaction.PrivilegeAction" method="{1}">
        <result name="success">/index.jsp</result>
    </action>

</package>

那么在访问资源的时候,就需要在项目名称后边加上名称空间的值:

这里写图片描述

现在就有一个很奇怪妙的事情发生了:在名称空间和资源路径的中间可添加任意的路径

这里写图片描述

但是呢,不能在名称空间之前加入不存在的路径:

这里写图片描述


其实这就涉及到了Struts中路径的匹配原则,我就拿随便拿个路径来举例子http://localhost:8080/user/a/a/privilege_login:

  • 首先,Struts会把请求的资源路径拿到,也就是privilege_login。
  • 然后在看看有没有/user/a/a这个名称空间;如果有,就返回结果
  • 如果没有,就看看有没有/user/a这个名称空间;如果有,就返回结果
  • 如果没有,再看看有没有/user这个名称空间;如果有,就返回结果
  • 直到最后,如果都没有找到,就报错!

看完这个例子,我们就可以知道为啥在名称空间和资源路径的中间可添加任意的路径,而不能在名称空间之前加入不存在的路径….这就是Struts的路径匹配原则..


Struts常量

Struts2默认的访问后缀是.action……

这里写图片描述

修改默认访问路径

有的时候,可能根据项目的需要…我想后缀名默认并不是.action,那我该怎么办呢??

我们在jar包上找到它的配置文件…

这里写图片描述

我们发现它的默认值是action,,

值得注意的是:两个逗号并不是多余的

我们不可能是直接修改jar包中的配置文件的,在struts.xml文件中提供了constant节点供我们修改struts的常量…

这里写图片描述

前面已经说了,两个逗号并不是多余的。那么直接在配置文件中配置action时,会怎么样:

<constant name="struts.action.extension" value="action"/>

这里写图片描述

也就是说,“,”号能够匹配空格键

举例子说明:

  • 如果配置后缀为action。那么后缀一定要写action
  • 如果配置后缀为action,do,。那么后缀可以是action,可以是do,也可以不写
  • 如果配置后缀为action,,。那么后缀可以是action,可以不写

Struts常用的常量

这里写图片描述


<struts>

    <!-- 0. 请求数据编码 -->
     <constant name="struts.i18n.encoding" value="UTF-8"/>
    <!-- 1. 修改Struts默认的访问后缀 -->
    <constant name="struts.action.extension" value="action,do,"></constant>
    <!-- 2. 修改xml自动重新加载 -->
    <constant name="struts.configuration.xml.reload" value="true"/>
    <!-- 3. 开启动态方法调用 (默认不开启)-->
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <!-- 4. 修改上传文件的最大大小为30M -->
    <constant name="struts.multipart.maxSize" value="31457280"/>


</struts>

上面的感觉需要讲解的就只有动态方法调用了……

那动态方法调用是怎么回事呢???这是样的:在action节点不配置method属性,在地址栏使用资源名称!方法名的方式去调用业务方法

这里写图片描述


跳转全局视图

为什么需要跳转全局视图?

首先,我们还是来看一个需求:现在我有两个Action,PrivilegeAction和CategoryAction

  • PrivilegeAction

public class PrivilegeAction extends ActionSupport {

    public String login() {
        System.out.println("我是登陆");

        return "success";
    }

    public String register() {
        System.out.println("我是注册");
        return "success";
    }
}
  • CategoryAction


public class CategoryAction extends ActionSupport {

    public String add() {
        System.out.println("我是添加");

        return "success";
    }

    public String find() {
        System.out.println("我是查找");
        return "success";
    }
}
  • 在struts.xml文件中配置

    <action name="privilege_*" class="privilegeaction.PrivilegeAction" method="{1}">
        <result name="success">/index.jsp</result>
    </action>

    <action name="category_*" class="privilegeaction.CategoryAction" method="{1}">
        <result name="success">/index.jsp</result>
    </action>

我们发现一个问题,只要是方法返回值是success,那么就跳转到首页….如果有大量Action方法返回的都是success,那么就要写很多很多个result节点了..

使用跳转全局视图

  • 代码就可以变成是这样子了,注意:global-results节点需要在action节点的上面

<package name="privilige" extends="struts-default" >

    <global-results>
        <result name="success">/index.jsp</result>
    </global-results>

    <action name="privilege_*" class="privilegeaction.PrivilegeAction" method="{1}">
    </action>

    <action name="category_*" class="privilegeaction.CategoryAction" method="{1}">
    </action>


</package>
  • 效果:

这里写图片描述


Action节点中的默认配置

一份相对完整的action节点是这样子的:

        <action name="privilege_*" class="privilegeaction.PrivilegeAction" method="{1}">
        </action>

method

如果我们不写method的话,默认执行的是execute()方法,execute()方法默认返回值是SUCCESS


public class BBAtion extends ActionSupport {

    @Override
    public String execute() throws Exception {
        System.out.println("我是execute()");

        return SUCCESS;
    }
}

这里写图片描述


class

如果不写class,class默认执行的action在struts-default有配置<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />

什么时候会不写class?就是需要跳转到WEB-INF目录下的资源的时候…..这就类似与Servlet需要跳转到WEB-INF下的资源。【Tomcat不允许直接访问WEB-INF资源】


        <!-- 什么情况不配置class? 即处理的aciton -->
        <!-- 答案: 当只是需要跳转到WEB-INF下资源的时候。 -->
         <action name="test2">
            <result name="success" >/WEB-INF/index.jsp</result>
         </action>

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
一文学会python基础知识 1. python 运行环境 1.1 脚本式环境 1.2 交互式环境 2. python 注释 3. 变量及变量命名 4. 关键词 BIFS 5. 标准操作符 6. 条件判断 7. 循环 8. python 数据类型 9. python 序列 9.1 序列-字符串(str) 9.2 序列-列表 9.3 序列-元组 10. 字典 11. 集合 12. python内存管理及可变、不可变对象 13. 函数 13.1 函数参数 13.2 return and yiled(生成器) 13.3 参数传递处理 ... 阅读详情

相关推荐

数据资产目录(SailCatalog)和数据地图(SailMap)

笔者接下来准备开发大数据平台(XSailboat)中的数据资产目录(SailCatalog)和数据地图(SailMap)相关的功能,本文用以记录笔者关于此部分功能的概念梳理和主体功能设计。

OkGogooXSailboat的博客 2336

Struts2之Action开发模式

一、Struts2模型     1、作用范围   Struts2提供了Map类型的request、session、application,可以从ActionContext对象中获得,它是Action执行的上下文。通常使用ActionContext对象的getContext()方法进行创建,如下, 1 Map request = ActionContext.getContex...

diluyi3709的博客 206

基于轻量级神经网络MobileNet V2的水果识别种类算法研究

本文阐述了一种基于轻量级卷积神经网络MobileNet V2的水果分类与识别算法研究。为了最大限度地促进机械收获,需要一个检测系统,它可以让我们识别不同类别的水果。一个相对未开发的想法是使用深度学习和人工智能算法,不仅可以检测水果的种类,还可以检测水果是否成熟。这可以证明是有利可图的,因为它可以提供作物生长状况以及成熟和未成熟果实的个体数量,以及决定是否是收获时间的有用信息。第一步对数据进行了预处理,数据预处理技术在众多的深度学习计算中起到了重要作用。

qq_43556680的博客 1647

Struts2 中.action和.do的奥秘和举例解析

.do和action之间的调用关系,.do如何定位后端的action方法等

sinat_26553595的博客 1911

详解电路设计中的RC电路

​ 一、什么是RC电路 RC电路是指由电阻R和电容C组成的电路,它是脉冲产生和整形电路中常用到 的电路。 常见的RC充、放电电路、RC积分电路合RC微分电路接下来详细讲解。 二、RC充、放电电路 RC充、放电电路如下图所示,下面通过充电和放电两个过程来分析此电路。 ​RC充、放电电路图 (1)RC充电电路 RC充电电路图如下图(a)所示 RC充电电路图及充电曲线图 ​由上图分析: 将上图a中开关S置于“1”处,电源E开始通过电阻R对电容C充电,由于刚开始充电时电容两端没有..

IT xiaobai 4万+

对冲策略与马丁结合ea的编程实践(五)核心是把两个品种合成一个新品种

在外汇、数字货币、期货交易甚至赌博中,马丁策略、网格策略是最常用的策略,也是最容易被理解的策略,但是如何克服单边行情、极端行情,是使用马丁策略最为头疼的事情,如加大间距、加大资金量,只能缓解,并不能根本解决这样的情况,所以使用时大部分时候都心里没底。 有没有一种正确的思路,让行情控制在震荡范围以内呢,这是今天我要向大家分享的一个思路,那就是对冲。大家看下图: 大家可以看到欧美(EURUSD)和镑美(GBPUSD),这两个品种,大部分时候走势是一致的,那么我们有没有可能把他们两个品种进行一下合成,比如买0.

omidsky的博客 3748

Struts.xml 配置文件详解注释

1.解决乱码问题 &lt;constant name="struts.i18n.encoding" value="utf-8"/&gt; //设置编码格式为utf-8 2.自定义扩展名 &lt;constant name="struts.action.extension" value="action,,wang"/&gt; //struts默认扩展名是a...

weixin_41504255的博客 743

基于Openrouter的API调用免费大模型

Openrouter 是一个 AI 模型聚合平台,整合了全球 200 多种主流 AI 模型,包括 GPT-4、Claude、Gemini 等,以及国产通义千问、DeepSeek 等。其核心优势是统一的 API 设计,开发者仅需少量代码即可与多个模型交互,还支持自动路由与回退机制。用户可通过 OpenAI SDK 或 LangChain 调用 Openrouter 中的模型。

MurphyStar的博客 6230

Struts2_010_Struts2可以受理的请求的扩展名

概述 默认可以接受的后缀名为.action 或者为空,在org.apache.struts2包下面的default-properties文件里面配置的:手工配置可接受的扩展名:修改default.properties其中的struts.action.extension(不建议) 在struts.xml中增加constant节点 <!-- 配置struts2的请求扩展名 1.修改defau

qq_33605778的博客 408

3、图像中文字信息提取技术全解析

本文全面解析了图像中文字信息提取(Text Information Extraction,TIE)的技术原理、挑战及应用领域。详细介绍了图像中三种主要文字形式:场景文字、字幕文字和文档文字的特点及提取难点。系统阐述了TIE技术的主要流程步骤,包括文字检测、定位、提取与增强、识别等关键阶段,并对主流技术方法进行了分类比较,包括基于连通组件、边缘、纹理等方法的优缺点分析。文章还介绍了多种其他提取技术,如二值化方法、混合方法、基于梯度的方法等,并提出了一种基于立体帧的新型场景文字提取方法,通过实验验证了该方法在召

ll5678的博客 121

DAVIS前言:事件相机资料调研

Event-Camera 资料集锦 1. 官网资料 假设了你买了事件相机,就可以在以下几个链接了解相关的参数和gui界面安装,如果不喜欢gui界面安装,可以第2节,安装相关的源码驱动。 DVS/DAVIS产品说明 等相关产品的软硬件介绍。 iniVation DV教程文档 给出在不同平台下的dvs-gui界面,可按照其说明进行相应的操作。 另外,Neuromorphic vision com...

Ian的博客 4513

struts2中Action的三种开发编写形式,ActionSupport,POJO

Action的三种编写方式: - 1、实现Action接口 需要实现execute()方法。 2、继承ActionSupport类 从struts2源码中,我们可以看到 ActionSupport类也实现了Action接口, 并且 Action接口中还定义了5个常量, 5个常量的值对应的是5个逻辑视图跳转页面 (跳转的页面还是需要自己来配置), 还定义了一个方法, execute方法。 这5...

Java开发,人工智能,边缘计算,致力于掌握前沿技术 582

ROSTCM6+Gephi的网络语义分析详细教程(附案例实战)

ROSTCM6是武汉大学沈阳教授研发编码的国内目前唯一的以辅助人文社会科学研究的大型免费社会计算平台。该软件可以实现微博分析、聊天分析、全网分析、网站分析、浏览分析、分词、词频统计、英文词频统计、流量分析、聚类分析等一系列文本分析。Gephi是一款开源免费跨平台基于JVM的复杂网络分析软件,可用于各种图形和网络的可视化和探索,是最受欢迎的网络可视化软件之一。

m0_64336780的博客 1万+

Struts2第三篇【Action开发方式、通配符、Struts常量、跳转全局视图、action节点默认配置】

前言上篇Struts博文已经讲解了Struts的开发步骤以及执行流程了…..对Struts的配置文件有了了解…..本博文继续讲解Struts在配置的时候一些值得要学习的细节…Action开发的三种方式在第一次我们写开发步骤的时候,我们写的Action是继承着ActionSupport类的…为啥我们继承了ActionSupport类呢?下面我就会讲解到继承ActionSupport类我们来看一下Act

zhong_fucheng 739

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

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

Struts2——配置

文章目录一、通配符二、Struts中路径的匹配原则2.1 通常情况2.2 匹配原则2.3 访问顺序三、Struts常量 一、通配符 参考:https://mp.weixin.qq.com/s/IwmSBorQlTefcGF1Qi9zwA 作用:简化代码。 PrivilegeAction.java public class PrivilegeAction extends ActionSupport ...

且行且珍惜 269

深度学习工具包 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")

Struts2 学习 (三)Struts2基本配置和核心业务

1. 通配符用于配置action:<package name="registerAction" extends="struts-default"> <action name="user_*" class="com.cityu.b_action.RegisterAction" method="{1}"> <result name = "success">/{1}.jsp</re

269

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Struts:修改struts的访问后缀(Action)

第一种方式: 在struts.xml的配置文件中添加 <constant name="struts.action.extension" value="do"></constant> 第二种方式: 在src下创建struts.properties 添加struts.action.extension=do 注:如果这样配置会覆盖struts.xml的配置 第三种方式: 在we...

Dan的博客 509

struts2 action扩展

一般情况下,struts2默认的action扩展名为action,这样就可以访问预定义的action,但是有的时候,我们想用.do或其他扩展访问action。 我们可以在struts.xml中的与之间添加一句代码 constant name="struts.action.extension" value="action,,do,webwork,xalead" /> 这样就可以用

liuyinghui523的专栏 811

Struts2 无后缀action请求

如果将Struts2的filter-mapping配置成 filter-mapping> filter-name>struts2filter-name> url-pattern>/*url-pattern> filter-mapping> 的话,struts2将可以处理无后缀的action请求,如 /demo/hello.action 和/demo

z69183787的专栏 1万+

【Struts2(一)】Strust2入门XML配置-action编写

1.1 案例需求 1.1.1 需求概述 CRM系统中有客户的显示的功能,效果如图: 我们实际的开发中会使用Struts2作为Web的架构  1.2 Struts2的概述 1.2.1 Struts2的概述 Struts是一种基于MVC模式的轻量级Web框架,它自问世以来,就受到了广大Web开发者的关注,并广泛应用于各种企业系统的开发中。目前掌握Struts框架几乎成为Web开发者的必...

风信子 4869

struts中的常用配置

struts.action.extension:该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts 2处理。 struts2中文件上传的二个限制,一个是struts.multipart.maxSize,如果不设置,struts2 的核心包下的default.properties文件里有默认的大小设置

arivn_jianming的博客 417

Struts2练习--基于注解方式Action配置

还是已登录来说明下这个Action的配置,这里要说的Action的配置不是在src/struts.xml中,而是用注解方式来进行配置的 前提是除了基本的那六个jar包之外,还需要一个struts-2.1.8.1\lib\struts2-convention-plugin-2.1.8.1.jar 不过struts.xml还是要有的 具体示例 Login.jsp   &lt;%@ page...

wangpingjing的博客 240

Struts2 Action扩展名的三种修改方法

http://wsjiang.iteye.com/blog/1126063 最近在做项目开发过程中犯了一个很低级的错误,在这里列举出来,供大家参考借鉴:我希望通过Url请求一个Action,最终通过服务器的处理能得到一个Json串,所以我在Url中体现这一特点,将action的扩展名写为xxaction.json,在web.xml 中将struts2过滤设置成了全部拦

xiaoxinxiaoxing的专栏 1151

Struts2 action的扩展名两种修改方法

转自:http://supercrsky.iteye.com/blog/372762 STRUTS2 ACTION的扩展名默认为.action,在struts1.X前为.do,如果要把STRUTS2的ACTION 的扩展名也改成.do可以按如下方法做。 方法一 struts

hjwang1的专栏 840

Struts2_02_Action访问与Action方法调用

一、Action访问路径Action的访问路径是由struts.xml文件中配置的Action所在包的命名空间,Action的名字和常struts.action.extension共同决定的 例如: &lt;constant name="struts.action.extension" value="action, ," /&gt; &lt;package name="def...

sktoo的专栏 310

struts2的struts.properties配置文件

struts.enable.DynamicMethodInvocation = true struts.action.extension=action,, struts.devMode = true #scan from other package struts.convention.package.locators.basePackage=cn struts.convention.pa

qq_38921377的博客 479
上一篇: Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
下一篇: Struts2第四篇【请求数据自动封装、Action得到域对象】
Java3y
Java3y 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 1万+粉丝 509原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值