第三章 Struts配置(第三~七节其他配置)

Jenkins中文显示不全?三步搞定Locale插件+汉化包的正确安装姿势 本文针对Jenkins界面中文显示不全问题,提供从原理到实战的深度解决方案。文章详细解析了Locale插件与中文语言包的核心机制,并分步指导如何通过配置JVM环境、正确安装插件及执行深度排查,彻底解决汉化顽疾,实现Jenkins界面的完美中文显示。 阅读详情

3.3节 Result配置

Action里提供了五个默认的返回值:

String SUCCESS = "success";

String NONE    = "none";

String ERROR   = "error";

String INPUT   = "input";

String LOGIN   = "login";

 

默认的一些配置

在package下有如下配置

<result-types>

<result-type name="dispatcher"

class="org.apache.struts2.dispatcher.ServletDispatcherResult"

    default="true" />

</result-types>

 

如果一个Result的type没有设定的话,默认为dispthcher。Dispatcher的意思是转向一个JSP等的资源。

另外如果Result的name没有设定的话,默认为SUCCESS。

 

一个完整的Result的声明如下:

<result name="success" type="dispatcher">

    <param name="location">/ThankYou.jsp</param>

</result>

考虑到默认值可以写成:

<result>

    <param name="location">/ThankYou.jsp</param>

</result>

另外也可以简写为:

<result>/ThankYou.jsp</result>

 

另外为了方便,可以在package中设置一些全局的result,例如:

<global-results>

  <result name="error">/Error.jsp</result>

  <result name="invalid.token">/Error.jsp</result>

  <result name="login" type="redirect-action">Logon_input</result>

</global-results>

 

动态结果

有些时候,在Action执行完毕之后才知道Result的指向,可以使用如下的方法:

Action

private String nextAction;

public String getNextAction() {

    return nextAction;

}

public String execute() throws Exception {

  return “next”;

}

 

struts.xml

<action name="fragment" class="FragmentAction">

  <result name="next" type="redirect-action">${nextAction}</result>

</action>

 

 

3.4节 ActionSupport

Action类不一定非要实现Action接口或者集成ActionSupport类,也就是说Action可以是一个POJO对象,只不过提供一个返回String的方法。如果Action类不实现Action接口,也不从ActionSupport集成,则Struts框架通过Java的反射机制(Reflection)来调用Action类中的处理方法。

Action类的处理方法需要满足以下要求

1 public

2 返回String,框架根据返回值决定迁移的目的

3 (可选)抛出Exception,让Struts框架统一处理异常

 

 

3.5节 Exception Handling

Struts可以以声明的方式处理Action类抛出的异常。以声明的方式处理是指:所有的Action类的处理方法抛出的Exception会被框架统一处理,之后定向到预先定义的Result。处理这些异常的Action,Result等可以动态的配置。

Struts2自带一个默认的配置:struts-default.xml,在这个文件中预先定义了一些基本的操作,其中Exception Handling也在其中,参看下述代码:

 

...

<interceptors>

    ...

    <interceptor name="exception"

          class="com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor"/>

    ...

</interceptors>

 

<interceptor-stack name="defaultStack">

    <interceptor-ref name="exception"/>

    <interceptor-ref name="alias"/>

    <interceptor-ref name="servlet-config"/>

    <interceptor-ref name="prepare"/>

    <interceptor-ref name="i18n"/>

    <interceptor-ref name="chain"/>

    <interceptor-ref name="debugging"/>

    <interceptor-ref name="profiling"/>

    <interceptor-ref name="scoped-model-driven"/>

    <interceptor-ref name="model-driven"/>

    <interceptor-ref name="fileUpload"/>

    <interceptor-ref name="checkbox"/>

    <interceptor-ref name="static-params"/>

    <interceptor-ref name="params"/>

    <interceptor-ref name="conversionError"/>

    <interceptor-ref name="validation">

        <param name="excludeMethods">input,back,cancel,browse</param>

    </interceptor-ref>

    <interceptor-ref name="workflow">

        <param name="excludeMethods">input,back,cancel,browse</param>

    </interceptor-ref>

</interceptor-stack>

...

 

要使用Struts2声明式异常处理,只需要将异常映射到result就可以了,可以用两种方法配置,一种方法是全局配置,针对所有的Action有效,另一种是针对具体的Action做配置,只针对具体的Action有效。

参看如下struts.xml 配置文件片段:

<package name="default">

      ...

      <global-results>

          <result name="login" type="redirect">/Login.action</result>

          <result name="Exception">/Exception.jsp</result>

      </global-results>

 

      <global-exception-mappings>

          <exception-mapping

exception="java.sql.SQLException" result="SQLException"/>

          <exception-mapping

exception="java.lang.Exception" result="Exception"/>

      </global-exception-mappings>

      ...

      <action name="DataAccess" class="com.company.DataAccess">

          <exception-mapping

exception="com.company.SecurityException" result="login"/>

          <result name="SQLException" type="chain">SQLExceptionAction</result>

          <result>/DataAccess.jsp</result>

      </action>

      ...

</package>

 

上述配置有如下结果

1 一个java.sql.SQLException异常将链接到SQLExceptionAction (上述文件中没有说明)

2 一个com.company.SecurityException将重新定位到login.action

3 其他从java.lang.Exception继承而来的Exception将会被定为到/Exception.jsp页面

 

3.6节 Intercepter拦截器

拦截器的运行时机在Action类运行之前和之后。拦截器使用Filter模式,将你需要执行的代码放在Action类处理方法之前或者之后执行。拦截器在开发程序的时候功能非常强大,通过使用拦截器可以完成校验,属性设置,安全,日志,程序剖析等功能。

 

拦截器可以彼此链接构成一个拦截器的栈,每一个拦截器本质上是一个Java类,都有一个常常的类名,为了方便使用,可以在Struts2框架中注册这些拦截器,例如:

<interceptor name="security" class="com.jpleasure.security.SecurityInterceptor"/>

  <interceptor-stack name="secureStack">

    <interceptor-ref name="security"/>

    <interceptor-ref name="defaultStack"/>

  </interceptor-stack>

</interceptors>

拦截器和拦截器栈可以混合使用来定义新的拦截器栈,在调用过程中,框架按照在拦截器栈中的顺序逐个调用这些拦截器。

 

可以在Package中定义默认的拦截器栈,例如:

<default-interceptor-ref name="secureStack"/>

当然每一个Action类也可以定义自己的拦截器栈,例如:

<action name="VelocityCounter"

                         class="org.apache.struts2.example.counter.SimpleCounter">

    <result name="success">...</result>

    <interceptor-ref name="defaultComponentStack"/>

</action>

 

3.7节 分离配置文件

可以在struts.xml中使用include标记将配置文件分离成不同的部分。

例如:

<!DOCTYPE struts PUBLIC

  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <include file="Home.xml"/>

    <include file="Hello.xml"/>

    <include file="Simple.xml"/>

    <include file="/util/POJO.xml"/>

</struts>

 
【Python】多分类算法—Random Forest 【Python】多分类算法—Random Forest 本文将主要就Random Forest(随机森林)的多分类应用进行描述,当然也可运用于二分类中 文章目录【Python】多分类算法—Random Forest前言一、pandas是什么?二、使用步骤1.引入库2.读入数据总结 前言 本文主要引用的是sklearn 一、pandas是什么? 示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。 二、使用步骤 1.引入库 代码如下(示例): import nump 阅读详情

相关推荐

LPC2124定时器实现跑马灯

文章目录一、keil 4新建工程 一、keil 4新建工程 1、Create New Project,注意,最好添加进一个新建好的文件夹里,keil不会帮你新建。 2、添加设备类型:NXP目录下的LPC2124 3、选择启动文件Startu.s 4、new 一个file,保存命名为.c文件 5、添加进project里,右击,add 选中,添加 6、设置编译输出.hex文件 ...

qq_37937830的博客 5753

Struts2学习之package配置

包配置 在struts框架中 ,是通过包配置来管理Action和拦截器的。在包中可以配置多个Action和拦截器。再struts.xml配置文件中,包是通过元素来配置的。 包配置在struts.xml中的配置格式如下: 包名" extends="包名" namespace="/命名空间">……   元素的常用属性如下所示: name:指定包名,是供其它包继承的时候使用

不如一默 810

Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包

联网情况下在命令终端CMD中输入“pip install numpy”即可自动安装,pandas和matplotlib同理一样方法进行自动安装。 工作的电脑不能上外网,所以不能通过直接输入pip命令来安装。 环境:电脑上已经安装了Python(没有安装的请参考其他教程)。 Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包的步骤如下: ...

dayou7738的博客 4942

使用Struts2开发Java Web应用程序(目录)

配套源代码网站:https://teamware.dev.java.net 第一部分 Struts入门    第一章 Struts2 概览(beta)    第二章 一个简单的Login 应用程序(beta)       Struts 2 概要    第三章Struts配置(beta)        第三章 Struts配置(第一节 struts.properties配置)  

Struts 2 的专栏 7万+

kettle写doris操作

文件在目录:doris-master\extension\kettle\assemblies\plugin\target\doris-stream-loader-plugins-9.4.0.0-343.zip。官方提供了doris stream load插件,下载源码编译后放到kettle的插件目录即可使用。地址:https://github.com/apache/doris.git。注意:需要doris插件或者kettle转换生成模板的私聊博主。使用PDmaner同步业务库生成建表语句。

weixin_44449054的博客 3030

第四节、C# 上位机面向对象编程详解(工控硬件继承实战版)

继承核心价值:在 C# 上位机工控开发中,继承的核心是通用逻辑复用与接口统一,将所有硬件的通用属性 / 方法封装到抽象基类,子类只需实现独有逻辑,大幅减少冗余代码。基类设计要点:优先使用抽象基类,合理分配访问修饰符(privateprotectedpublic),定义通用事件与虚方法,提供资源释放机制,兼顾复用性与扩展性。子类设计要点:通过: base()调用基类构造函数,强制实现抽象方法(保证接口统一),选择性重写虚方法(实现独有逻辑),复用基类的protected成员。多设备管理。

kylezhao2019的博客 787

第七节:Struts2-类型转换

类型转换的作用: 实现了表示层与逻辑层数据类型之间的转换。(JSP页面只有String类型,Action层有各种类型),这种数据转换可以放在Action处理类中实现,因为几乎每个Action都涉及到数据转换所以抽出来做了自动(基本类型、OGNL表达式)的类型转换拦截器。 1.处理请求参数 将JSP页面(也可能是其他视图类型)提交的数据(字符串类型),转换成Action中设定的复杂类型属性

我是xxxx 613

一种基于频域滤波法消除干扰项与角谱法重构技术的数字全息显微台阶形貌测量实例分析

一种基于频域滤波法消除干扰项与角谱法重构技术的数字全息显微台阶形貌测量实例分析

简单光学 2034

使用Struts2开发Java Web应用程序

原文: http://blog.youkuaiyun.com/struts2/archive/2007/08/01/1721752.aspx 配套源代码网站:https://teamware.dev.java.net 第一部分 Struts入门    第一章 Struts2 概览(beta)    第二章 一个简单的Login 应用程序(beta)       Struts 2 概要

cool_rain_man的专栏 1085

模拟IC设计避坑:手把手教你用Cadence仿真恒定跨导轨到轨运放(附完整工艺库文件)

本文详细解析了使用Cadence仿真恒定跨导轨到轨运放的全流程,涵盖电路原理、工艺库配置、尺寸设计及仿真分析。通过1:3电流镜补偿技术实现跨导稳定,提供CSMC 0.25um工艺下的实战案例,帮助工程师规避设计陷阱,提升模拟IC设计效率。

weixin_30952535的博客 494

深入Google DroidGuard:剖析其自定义虚拟机如何守护Android应用安全(附pcbc文件机制解析)

本文深入解析Google DroidGuard自定义虚拟机如何通过独特的架构设计和加密机制保护Android应用安全。DroidGuard采用动态密钥派生、全加密执行环境和pcbc文件机制,有效防御逆向工程和自动化攻击,为移动安全提供新思路。

weixin_34254464的博客 307

struts2开发web

[置顶] 使用Struts2开发Java Web应用程序(目录) 分类: Struts2 2007-08-01 22:12 57367人阅读 评论(48) 收藏 举报 strutsjavaweblocalizationjquerydojo 配套源代码网站:https://teamware.dev.java.net   第一部分 Struts入门     第一章 Struts2...

LIXG425的专栏 187

Transformer实战(1)——词嵌入技术详解

词嵌入的核心思想是,通过将词语表示为稠密的向量,使得计算机可以更有效地处理和理解文本中的语义关系。在本节中,我们学习了单词分布式表示的概念及其实现,包括静态嵌入和动态嵌入,实现了 Word2Vec 和 GloVe 模型,并介绍了如何使用 Gensim API 探索嵌入空间。

盼小辉丶的博客 1万+

Struts2的专栏

第一部分 Struts入门    第一章 Struts2 概览(beta)    第二章 一个简单的Login 应用程序(beta)    第三章Struts配置(beta)        第三章 Struts配置(第一节 struts.properties配置)        第三章 Struts配置(第二节 Actin配置)        第三章 Struts配置(第三~七节其他配置)

518

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

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

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

Struts2,大爷你好!第二天补一发笔记

第四节Struts2处理传入多个值处理数目不定的字符串。多选框 String[] students处理数目不定的JavaBean对象 List<student> Student第五节:struts.xml配置 说明例:<package name="包名" namespace="/fore" abstract="true" extends="strus-default...

weixin_30485799的博客 100

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Struts2学习拦截器

介绍 拦截器之所以称为拦截器,是因为他可以在Action执行前后拦截调用。 Struts 2 将它的核心功能放到拦截器中实现而不是分散到 Action 中实现, 有利于系统 的解耦, 使得功能的实现类似于个人电脑的组装, 变成了可插拔的。 需要某个功能就“ 插 入” 一个拦截器, 不需要某个功能就“ 拔出” 一个拦截器。 你可以任意组合拦截器来为 Action 提供附加的功能, 而不需要修...

茨时代べ 的博客 200

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

上一篇: 第三章 Struts配置(第二节 Actin配置)
下一篇: 附录一 Maven2 安装
struts2
博客等级 码龄19年 885粉丝 103原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值