20090317-20090319 (struts)

本文详细介绍了Struts2框架的基本配置与使用方法,包括拦截器、验证、结果类型等关键组件的工作原理及配置技巧。

Conversion?
Validation?
How to bind values from request to action and from action to jsp?
Struts tag library?


Validation can be described through an XML document, or using annotations. The XML document is named after the Action being validated with a "-validation" suffix.


The convention plugin use certain convention so that you almost don't need to do any configuration.


Interceptors will be executed before and after action, PreResultListeners after action executes but before evaluating result.
Interceptors can be group as interceptor stack, them can be put in action declaration or set as default interceptor of the package.
When apply to all actions, you can use "excludeMethods" and "includeMethods" to determine whether or not to apply to a method.
Use <param> to override "excludeMethods" and "includeMethods" of an interceptor or interceptor stack (<interceptor-name>.<parameter-name>)


A Struts 2 Action instance is created for every request and do not need to be thread-safe. Conversely, Interceptors are shared between requests and must be thread-safe.


Swtich to another action is not recommended. Use ChainingInterceptor to make variables in source action visible to target action.
Actions should be treated as a Transaction Script, rather than as methods in a Business Facade. Ideally, Action classes should be as short as possible. All the core logic should be pushed back to a support class or a business facade, so that Actions only call methods. Actions are best used as adapters, rather than as a class where coding logic is defined.
Action is not suitable for reuse, the lack of support makes it hard to manage, reuse interceptor or business facade. This is what ES don't understand and one of the reasons why it's so ugly.


Common static content that is needed by the framework (JavaScript and CSS files, etc.) is served automatically by the FilterDispatcher filter. Any request starting with "/struts/" denotes that static content is required, and then mapping the value after "/struts/" to common packages in the framework and, optionally in the application's class path.
org.apache.struts2.static
template
(configured in web.xml for the FilterDispatcher filter)


org.apache.struts2.dispatcher.FilterDispatcher
config - a comma-delimited list of XML configuration files to load.
actionPackages - a comma-delimited list of Java packages to scan for Actions.
configProviders - a comma-delimited list of Java classes that implement the ConfigurationProvider interface that should be used for building the Configuration.
loggerFactory - The class name of the LoggerFactory implementation.
* - any other parameters are treated as framework constants.
If we change the filter mapping to something else, for example /*.html, we must take this in to account and extract the content that would normally be served from the Struts 2 jar files, or some other solution.


Use struts.properties to configurate struts (note the different between struts.xml), all properties can also be set using Constant Configuration in an XML configuration file.


The default (struts.xml) file and should reside on the classpath of the webapp.


A base configuration file named struts-default.xml is included in the struts2.jar file. This file is automatically included into struts.xml file to provide the standard configuration settings without having to copy them.
To exclude the struts-default.xml or to provide your own version, see the struts.configuration.files setting in struts.properties.


<bean>
"class", value used to create or retrieve a bean object, may be a class name or a spring bean name or other.
"type" and "name", used to inject this bean in to xwork framework, values for "name" should be unique among "type".
"static", used to inject values inside xwork framework in to this bean, setter methods should be marked using "@inject".


<constant>
Use <constant name="struts.devMode" value="true" /> in struts's xml, and use "name=value" in properties file, use
<init-param>
  <param-name>struts.devMode</param-name>
  <param-value>true</param-value>
</init-param>
in web.xml
The priority is as follow, note that web.xml has the highest priority.
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml


<action>
<default-action-ref>


Wildcard Method, e.g.
<action name="*Crud" class="example.Crud" method="{1}">
<action name="List*s" class="actions.List{1}s">
  <result>list{1}s.jsp</result>
</action>
* is not greedy, consider use "ListSponsors" against the previous example.
*  Matches zero or more characters excluding the slash ('/') character.
** Matches zero or more characters including the slash ('/') character.
\* matches the character asterisk ('*'), and
\\ matches the character backslash ('\').
In the action mapping and action results, the wildcard-matched values can be accessed with the token {N} where N is a number from 1 to 9 indicating which wildcard-matched value to substitute. The whole request URI can be accessed with the {0} token.
The same for configuration file: e.g. "Crud_input-validation.xml", "Crud_delete-conversion.xml"
Dynamic Method Invocation ("Category!create.action") is not recommended by struts, use Wildcard Method instead.
<action name="*">
  <result>/{1}.jsp</result>
</action>
It's important to put a "catchall" wildcard mapping like this at the end of your configuration so it won't attempt to map every request!


Post back, first render a page using an alternate method, like input and then have it submit back to the default execute method.
<s:form>
  <s:textfield label="Please enter your name" name="name"/>
  <s:submit/>
</s:form>
The form simply submits back to the action that created it.


ResultType default.
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>


The framework will first look for a local result nested in the action. If a local match is not found, then the global results are checked.
<global-results>
  <result name="error">/Error.jsp</result>
  <result name="invalid.token">/Error.jsp</result>
  <result name="login" type="redirectAction">Logon!input</result>
</global-results>


Dynamic Results
<action name="fragment" class="FragmentAction">
  <result name="next" type="redirectAction">${nextAction}</result>
</action>


<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="myclasses.SomeUnknownHandler"/>
<unknown-handler-stack>
  <unknown-handler-ref name="handler1" />
  <unknown-handler-ref name="handler2" />
</unknown-handler-stack>
Handles unknow action/method/result, and return an action/method/result to be used.


First use ExceptionMappingInterceptor, it will push exception to ValueStack using:
exception      - The exception object itself 
exceptionStack - The value from the stack trace 
Local exception handling:
<action name="DataAccess" class="com.company.DataAccess">
  <exception-mapping exception="com.company.SecurityException" result="login"/>
  <result name="SQLException" type="chain">SQLExceptionAction</result>
</action>
Global exception handling:
<global-exception-mappings>
  <exception-mapping exception="java.sql.SQLException" result="SQLException"/>
  <exception-mapping exception="java.lang.Exception" result="Exception"/>
</global-exception-mappings>
<global-results>
  <result name="login" type="redirect">/Login.action</result>
  <result name="Exception">/Exception.jsp</result>
</global-results>

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值