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>
分享到:
相关推荐
包含Struts2框架的核心类库,以及Struts2的第三方插件类库 struts2-core-2.0.14 xwork-2.0.7 ognl-2.6.11 commons-logging-1.0.4 freemarker-2.3.8 等等。
在"jakarta-struts-1.1.zip"这个压缩包中,包含了Jakarta Struts 1.1版本的核心组件和相关资源。 `struts-documentation.war`文件是一个预打包的Web应用,通常用于部署到Servlet容器,如Tomcat或Jetty。这个WAR文件...
spring-webmvc-struts.jar对Struts和Spring整合时需要用到的包
在基础配置完成后,教程将深入讲解Struts的核心组件,如Action、ActionForm、DispatcherServlet(即Struts的前端控制器)以及配置文件struts-config.xml。Action是处理用户请求的核心类,ActionForm用于封装表单数据...
Struts2漏洞检查工具2019版 警告: 本工具为漏洞自查工具,请勿非法攻击他人网站! ==漏洞编号==============影响版本=========================官方公告==========================================影响范围====...
### Struts2技术详解 #### 一、Struts2简介 Struts2是Apache基金会旗下的一个开源项目,作为MVC(Model-View-Controller)设计模式的一种实现,它被广泛应用于Java Web应用的开发中。Struts2为Web应用提供了一个...
JavaEE主流开源框架-Struts部分rmvb格式. JavaEE主流开源框架-Struts部分rmvb格式. JavaEE主流开源框架-Struts部分rmvb格式. JavaEE主流开源框架-Struts部分rmvb格式. JavaEE主流开源框架-Struts部分rmvb格式. ...
本科毕业论文---基于struts和hibernate的教学答疑系统.doc
基于java的开发源码-Struts验证码插件 JCaptcha4Struts2.zip 基于java的开发源码-Struts验证码插件 JCaptcha4Struts2.zip 基于java的开发源码-Struts验证码插件 JCaptcha4Struts2.zip 基于java的开发源码-Struts...
轻量级J2EE企业应用实战--Struts+Spring+Hibernate整合开发 part2
JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包JavaSSH框架strutsjAR包...
Struts是Java Web开发中的一个经典框架,由Apache软件基金会维护,主要负责处理MVC(Model-View-Controller)架构中的Controller部分。本篇文章将深入探讨Struts框架的核心概念、工作原理及其在实际开发中的应用。 ...
Struts2是一个非常流行的Java MVC框架,用于构建企业级Web应用程序。然而,它在历史上曾出现过多个安全漏洞,其中最著名的就是“Struts2漏洞”。这个标题和描述提到的"struts2-scan"是一种工具,专门用来检测Struts2...
该工具的打开路径为:\Struts2VulsTools-2.3.20190927\Test\bin\Release\Text.exe 2019-09-25: 优化部分EXP在部分情况下被WAF拦截的问题,提高检测成功率,优化自定义上传路径exp,文件所在目录不存在时自动创建...
《轻量级J2EE企业应用实战--Struts+Spring+Hibernate整合开发》图书配套源码part1
《轻量级J2EE企业应用实战--Struts+Spring+Hibernate整合开发》源码.part6
Struts最早是作为Apache Jakarta项目的组成部分,项目的创立者希望通过对该项目的研究,改进和提高JavaServer Pages 、Servlet、标签库以及面向对象的技术水准 Struts2和Struts1的不同
org-netbeans-modules-web-frameworks-struts2lib-v2_2_3.nbm