- 浏览: 24706 次
- 性别:
- 来自: 武汉
最新评论
-
liansc:
...
servlet学习手册 -
PointOnLine:
不是吧,我问别人的时候,别人说可以的,叫我在网上去查,我没查到 ...
用spring的bean来初始化一个serlvet 应该怎样去初始化呢 -
liujia9234:
可能不行,servlet是由web.xml加载的,可以用str ...
用spring的bean来初始化一个serlvet 应该怎样去初始化呢 -
fcoffee:
servlet是处在spring容器之外的东西, 所以spri ...
用spring的bean来初始化一个serlvet 应该怎样去初始化呢 -
kimmking:
PointOnLine 写道最近做项目时,用spring的be ...
用spring的bean来初始化一个serlvet 应该怎样去初始化呢
Troubleshooting guide migrating from Struts 2.0.x to 2.1.x
<!--[if !vml]--><!--[endif]-->About the Migration guide
This guide describes how to migrate an existing Struts 2.0.x application to Struts 2.1.x. It is intended to be read from top to bottom but you may skip-ahead to known problems and common exceptions. Please edit this page or provide comments if you encounter additional issues.
Update Dependencies
Update your project dependences to use struts2-core-2.1.x and the plugins struts2-core-2.1.x.
<!--[if !vml]--><!--[endif]-->
There have been significant changes to the Configuration API between 2.0 and 2.1. Third-party plugins for 2.0 may not be compatible with 2.1.x.
Maven users can update their project's pom.xml to reference the new core and plugin versions. Ensure no dependencies in the freemarker groupId are used as the latest version used by Struts is now under the org.freeemarker groupId and will cause classpath conflicts.
If you need releases not considered General Availability you can use a staging repository where they are usually available:
<repositories>
<repository>
<id>struts2.1.2-staging</id>
<name>Struts 2.1.2 staging repository</name>
<layout>default</layout>
<url>http://people.apache.org/builds/struts/2.1.2/m2-staging-repository/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Non-Maven users can can download the jars and dependencies in a Distribution 2.1.2 <!--[if !vml]--><!--[endif]-->
<!--[if !vml]--><!--[endif]-->
DELETE OLD VERSIONS NOW: It's essential that old versions of the jars are removed from your project as well as the deployment directories. Don't trust your IDE to delete unused versions.
eg. Your application is now be dependent on xwork-2.1.x, not xwork-2.0.x. Ensure xwork-2.0.x is completely removed or you will encounter compile-time and run-time exceptions.
Update Custom Type Converters
If your project implements custom type converters you may need to change the imports statements to use the com.opensymphony.xwork2.conversion package. Failing to do so will cause a compile-time error.
Before:
import com.opensymphony.xwork2.util.TypeConversionException;
After:
import com.opensymphony.xwork2.conversion.TypeConversionException;
Update struts.xml Configuration
Results and Interceptors have been renamed to use camelCase instead of hyphenated names (eg. now redirectAction instead of redirect-action).
Review all custom interceptor stacks, interceptor refs and results in struts.xml and remove the hyphen.
Interceptors:
From
To
external-ref
externalRef
model-driven
modelDriven
static-params
staticParams
scoped-model-driven
scopedModelDriven
servlet-config
servletConfig
token-session
tokenSession
Results:
From
To
redirect-action
redirectAction
plaintext
plainText
<!--[if !vml]--><!--[endif]-->
Forgetting to rename an interceptor or result reference will prevent your WebApp from starting. The following is a typical stacktrace for an invalid result type.
SEVERE: Exception starting filter struts2
Unable to load configuration. - action - file:/home/giaz/code/.metadata/.plugins/
com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:370)
...
Caused by: Error building results for action ScheduleJob in namespace - action - file:/home/giaz/code/.metadata/.plugins/
com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:372)
... 30 more
Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success' - result -
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
Migrate plugin configuration
Tiles 2
If you use the Tiles 2 plugin, check your tiles.xml file(s) to ensure they contain a DOCTYPE.
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"><tiles-definitions>...<!--[if !vml]--><!--[endif]-->
A missing DOCTYPE in your Tiles configuration will prevent your WebApp from starting. The following is a typical stacktrace for a missing Tiles DOCTYPE.
INFO: Initializing Tiles2 container. . .Nov 22, 2007 11:38:11 AM org.apache.commons.digester.Digester errorSEVERE: Parse Error at line 2 column 19: Document is invalid: no grammar found.org.xml.sax.SAXParseException: Document is invalid: no grammar found.
Ajax Theme / Dojo
If your WebApp uses the ajax theme bundled with Struts 2.0 (ajax tags), you need to update every pageas the Dojo support has been moved into a separate plugin and tag library.
1. Add the Dojo plugin as a new dependency for your project
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-dojo-plugin</artifactId> <version>2.1.1</version> </dependency>2. Modify ALL pages that use the ajax theme to use the Dojo tag library.
For each page there are three tasks to complete:
reference the new Dojo tag library
update the head tag
update all ajax themed tags
check inline scripts
check inline widgets
<!--[if !vml]--><!--[endif]-->
If this is a major undertaking for your application, it's recommended to modify, test and validate each page one at a time.
Reference the new Dojo Tag Library
Reference the new taglib in your JSP or FTL pages.
Before
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags"%>After
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><!--[if !vml]--><!--[endif]-->
Many pages will require both the core and dojo tags. The sx: prefix is preferred for the Dojo tags.
Update the head tag
Review the new attributes of the new head <!--[if !vml]--><!--[endif]--> tag. You need to decide which values for the cache, compressed, parseContent and extraLocales attributes are appropriate for your application. These settings have major performance implications.
Before:
<s:head theme="ajax"/>After:
<sx:head parseContent="true"/>Update all ajax themed tags
Some tags are available only in the Dojo plugin taglib. It will be immediately obvious from your IDE that these tags need to change to the sx: prefix.
Some tags are available in both the core and Dojo plugin taglibs. Any tag that uses the ajax theme needs to be changed to the sx: prefix.
Before:
<s:url id="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><s:div id="jobStatus" theme="ajax" href="%{jobStatus}" updateFreq="5000" indicator="indicator"></s:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/>After:
<s:url var="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><sx:div id="jobStatus" href="%{#jobStatus}" updateFreq="5000" autoStart="true" indicator="indicator"></sx:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/><!--[if !vml]--><!--[endif]-->
If you forget to migrate a tag reference from the core to the dojo plugin you will receive an exception similar to the one below:
2008-04-19 14:32:30,475 ERROR [http-8443-Processor23] [[jsp]] Servlet.service() for servlet jsp threw exceptionorg.apache.jasper.JasperException: No tag "datetimepicker" defined in tag library imported with prefix "s"
Check inline javascript
If your ajax html results contain inline javascript that needs to be executed after updating the DOM, ensure your ajax tags set executeScripts="true" and separateScripts="true". These attributes instruct the widget to search for javascript in the result,
extract it, update the DOM with the result and then execute the javascript.
eg. The following bind will execute scripts within the result when the Submit button is pressed
<s:submit value="Submit" id="submit3" /><sx:bind targets="div1" highlightColor="#ffffcc" highlightDuration="500" sources="submit3"events="onclick" href="%{#fragment3Url}" errorNotifyTopics="/error" executeScripts="true"separateScripts="true"/>Check inline widgets
If your ajax html results include dojo widgets, ensure the head tag's parseContent attribute is true. This instructs dojo to parse the ajax responses for widgets. Note that Struts2.0 always enabled this feature and it could not be turned off. Struts2.1 disables this feature and allows it to be turned on as there is a significant performance impact.
Convert EL expressions to OGNL
Struts2.1 tags do not allow evaluation of JSP EL within their attributes. Instead, Struts2 tags evaluate attribute values as OGNL. Allowing both expression languages within the same attribute opens major security vulnerabilities.
todo: how to convert
<!--[if !vml]--><!--[endif]-->
Forgetting to convert attributes to OGNL expressions will produce exceptions similar to the one below:
org.apache.jasper.JasperException: /example.jsp(8,6) According to TLD or attribute directive in tagfile, attribute value does not accept any expression
Reduce verbose logging
Struts 2.1 introduces more verbose logging than Struts 2.0. While extremely valuable, some users may find these annoying.
Missing Properties
This message states that the framework searched for a property in the value stack and failed to find it.
2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir]2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir]2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir]2008-04-19 14:21:08,178 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [org.apache.catalina.jsp_file]To hide these messages, turn off the WARN level logging for OgnlValueStack.
eg. Include a new limit category in your log4j.xml file (only log errors or worse):
<category name="com.opensymphony.xwork2.ognl.OgnlValueStack"> <priority value="error"/> </category>TextProvider missing keys
These messages state that the framework searched for text in a resource bundle and failed to find it.
2008-04-19 14:32:30,106 WARN [http-8443-Processor23] [TextProviderHelper] The first TextProvider in the ValueStack(package.Action) could not locate the message resource with key 'companyDetails.addressId'2008-04-19 14:32:30,107 WARN [http-8443-Processor23] [TextProviderHelper] The default value expression'companyDetails.addressId' evaluated to '10'To hide those messages, turn off the WARN level logging for TextProviderHelper.
eg. Include a new limit category in your log4j.xml file (only log errors or worse):
<category name="org.apache.struts2.util.TextProviderHelper"> <priority value="error"/> </category>
Update Unit Tests
There are two known major migration issues affecting user's unit tests.
The Configuration API now uses a Builder pattern
The ActionContext.getContext() method does not create a context on demand.
Review the Unit Tests included with Struts2 for recommended practices to setup the Configuration and context.
A quick fix for ActionContext.getContext() returning null :
ConfigurationManager configurationManager = new ConfigurationManager(); configurationManager.addContainerProvider(new XWorkConfigurationProvider()); Configuration config = configurationManager.getConfiguration(); Container container = config.getContainer(); ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); stack.getContext().put(ActionContext.CONTAINER, container); ActionContext.setContext(new ActionContext(stack.getContext())); assertNotNull(ActionContext.getContext());Trouble-shooting
The issues are listed in the same order as encountered after changing jars over from 2.0.x to 2.1.x. Noteworthy, the migration was done under the following setup: Fedora core 6, JDK 1.6.0_2 and Tomcat 6.0.10 running from MyEclipse plugin.
Result type "redirect-action" was renamed to "redirectAction":
SEVERE: Exception starting filter struts2Unable to load configuration. - action - file:/home/giaz/code/.metadata/.plugins/ com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:370)...Caused by: Error building results for action ScheduleJob in namespace - action - file:/home/giaz/code/.metadata/.plugins/ com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:372) ... 30 moreCaused by: There is no result type defined for type 'redirect-action' mapped with name 'success' - result - file:/home/giaz/code/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/ WEB-INF/classes/struts.xml:40:50 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:616) ... 35 moreThe struts.xml before:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirect-action"> <param name="actionName">ListDisplayOptimizationJobStatus</param> </result> <result name="error" type="tiles">webui.requestFailed</result></action>To resolve this issue modify the struts.xml action definition to:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirectAction"> <param name="actionName">ListDisplayOptimizationJobStatus</param> </result> <result name="error" type="tiles">webui.requestFailed</result></action>or to:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirect">ListDisplayOptimizationJobStatus.action</result> <result name="error" type="tiles">webui.requestFailed</result></action>
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->Tiles 2.1.x plugin tiles.xml now requires DOCTYPE:
Problem Symptom:
Nov 22, 2007 11:38:11 AM org.apache.tiles.impl.BasicTilesContainer initINFO: Initializing Tiles2 container. . .Nov 22, 2007 11:38:11 AM org.apache.commons.digester.Digester errorSEVERE: Parse Error at line 2 column 19: Document is invalid: no grammar found.org.xml.sax.SAXParseException: Document is invalid: no grammar found. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)<!--[if !vml]--><!--[endif]-->
Reason for this
This is due to the fact that Tiles 2.0.5 now turns validation on as default.
The tiles.xml page before:
<?xml version="1.0" encoding="ISO-8859-1" ?><tiles-definitions/>To resolve the issue simply add:
<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://struts.apache.org/dtds/tiles-config_2_0.dtd"><tiles-definitions/><s:head theme="ajax"/> is obsolete, use a different theme:
Problem Symptom: Accessing any page that includes <s:head theme="ajax"/> produces the following error:
Nov 22, 2007 1:54:51 PM freemarker.log.JDK14LoggerFactory$JDK14Logger errorSEVERE:Expression parameters.parseContent is undefined on line 45, column 28 in template/ajax/head.ftl.The problematic instruction:----------==> ${parameters.parseContent?string} [on line 45, column 26 in template/ajax/head.ftl]----------Java backtrace for programmers:----------freemarker.core.InvalidReferenceException: Expression parameters.parseContent is undefined on line 45, column 28 in template/ajax/head.ftl. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124) at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)Resolution is to either remove the "<s:head theme="ajax"/>" or use a different theme e.g. <s:head theme="xhtml" />
Ajax UI tags were moved to the new dojo plugin, use /struts-dojo-tags taglib instead of (or in addition to) /struts-tags:
Problem Symptom: Accessing a page containing ajax UI tags through using the struts 2 taglib will produce the following error:
SEVERE: Servlet.service() for servlet jsp threw exceptionorg.apache.jasper.JasperException: /jsp/list/listOptimizationJobStatus.jsp(6,0) Attribute href invalid for tag div according to TLD at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)JSP before migration:
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="display" uri="http://displaytag.sf.net" %><%@ taglib prefix="s" uri="/struts-tags"%><s:url id="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><s:div id="jobStatus" theme="ajax" href="%{jobStatus}" updateFreq="5000" indicator="indicator"></s:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/>Resolution is to import and use struts-dojo-tags plugin instead:
<%@ page contentType="text/html; charset=UTF-8" language="java" %><%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><s:url var="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><sx:div id="jobStatus" href="%{#jobStatus}" updateFreq="5000" autoStart="true" indicator="indicator"></sx:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/><!--[if !vml]--><!--[endif]-->
Other Ajax UI tags were also moved to the dojo plugin
Note the use of remote div is now through the dojo plugin taglib sx. Other ui tags are also no longer available through the /struts-tags taglib but only through the /struts-dojo-tags taglib: datetimepicker and autocompleter.
User-defined converter (subclassing StrutsTypeConverter) will no longer be needed when using datetimepicker:
Problem Symptom: Your custom StrutsTypeConverter implementation does not longer work in version 2.1.x. In 2.0.x you needed to implement a custom StrutsTypeConverter e.g. StringToDateConverter to be able to parse and convert to Date the String posted from a datetimepicker control into the action. In version 2.0.x datetimepicker was posting a String formatted as specified in the "displayFormat" field e.g.
<%@ taglib prefix="s" uri="/struts-tags"%><s:datetimepicker label="Begin Date" name="beginDate" displayFormat="yyyy.MM.dd">In version 2.1.x datetimepicker will post a String Date in RFC 3339 format, so you can define your setter to receive a Date directly and avoid using converters for this purpose e.g.
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><sx:datetimepicker label="Begin Date" name="beginDate" displayFormat="yyyy.MM.dd">ActionMappingParams
Parameters set by the action mapping are not set/not available through ParameterAware (This change is only needed when going to 2.1.x (where x>0))
These are now only available if you use the new interceptor named "actionMappingParams".
<!--[if !vml]--><!--[endif]-->About the Migration guide
This guide describes how to migrate an existing Struts 2.0.x application to Struts 2.1.x. It is intended to be read from top to bottom but you may skip-ahead to known problems and common exceptions. Please edit this page or provide comments if you encounter additional issues.
Update Dependencies
Update your project dependences to use struts2-core-2.1.x and the plugins struts2-core-2.1.x.
<!--[if !vml]--><!--[endif]-->
There have been significant changes to the Configuration API between 2.0 and 2.1. Third-party plugins for 2.0 may not be compatible with 2.1.x.
Maven users can update their project's pom.xml to reference the new core and plugin versions. Ensure no dependencies in the freemarker groupId are used as the latest version used by Struts is now under the org.freeemarker groupId and will cause classpath conflicts.
If you need releases not considered General Availability you can use a staging repository where they are usually available:
<repositories>
<repository>
<id>struts2.1.2-staging</id>
<name>Struts 2.1.2 staging repository</name>
<layout>default</layout>
<url>http://people.apache.org/builds/struts/2.1.2/m2-staging-repository/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Non-Maven users can can download the jars and dependencies in a Distribution 2.1.2 <!--[if !vml]--><!--[endif]-->
<!--[if !vml]--><!--[endif]-->
DELETE OLD VERSIONS NOW: It's essential that old versions of the jars are removed from your project as well as the deployment directories. Don't trust your IDE to delete unused versions.
eg. Your application is now be dependent on xwork-2.1.x, not xwork-2.0.x. Ensure xwork-2.0.x is completely removed or you will encounter compile-time and run-time exceptions.
Update Custom Type Converters
If your project implements custom type converters you may need to change the imports statements to use the com.opensymphony.xwork2.conversion package. Failing to do so will cause a compile-time error.
Before:
import com.opensymphony.xwork2.util.TypeConversionException;
After:
import com.opensymphony.xwork2.conversion.TypeConversionException;
Update struts.xml Configuration
Results and Interceptors have been renamed to use camelCase instead of hyphenated names (eg. now redirectAction instead of redirect-action).
Review all custom interceptor stacks, interceptor refs and results in struts.xml and remove the hyphen.
Interceptors:
From
To
external-ref
externalRef
model-driven
modelDriven
static-params
staticParams
scoped-model-driven
scopedModelDriven
servlet-config
servletConfig
token-session
tokenSession
Results:
From
To
redirect-action
redirectAction
plaintext
plainText
<!--[if !vml]--><!--[endif]-->
Forgetting to rename an interceptor or result reference will prevent your WebApp from starting. The following is a typical stacktrace for an invalid result type.
SEVERE: Exception starting filter struts2
Unable to load configuration. - action - file:/home/giaz/code/.metadata/.plugins/
com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:370)
...
Caused by: Error building results for action ScheduleJob in namespace - action - file:/home/giaz/code/.metadata/.plugins/
com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:372)
... 30 more
Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success' - result -
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
Migrate plugin configuration
Tiles 2
If you use the Tiles 2 plugin, check your tiles.xml file(s) to ensure they contain a DOCTYPE.
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"><tiles-definitions>...<!--[if !vml]--><!--[endif]-->
A missing DOCTYPE in your Tiles configuration will prevent your WebApp from starting. The following is a typical stacktrace for a missing Tiles DOCTYPE.
INFO: Initializing Tiles2 container. . .Nov 22, 2007 11:38:11 AM org.apache.commons.digester.Digester errorSEVERE: Parse Error at line 2 column 19: Document is invalid: no grammar found.org.xml.sax.SAXParseException: Document is invalid: no grammar found.
Ajax Theme / Dojo
If your WebApp uses the ajax theme bundled with Struts 2.0 (ajax tags), you need to update every pageas the Dojo support has been moved into a separate plugin and tag library.
1. Add the Dojo plugin as a new dependency for your project
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-dojo-plugin</artifactId> <version>2.1.1</version> </dependency>2. Modify ALL pages that use the ajax theme to use the Dojo tag library.
For each page there are three tasks to complete:
reference the new Dojo tag library
update the head tag
update all ajax themed tags
check inline scripts
check inline widgets
<!--[if !vml]--><!--[endif]-->
If this is a major undertaking for your application, it's recommended to modify, test and validate each page one at a time.
Reference the new Dojo Tag Library
Reference the new taglib in your JSP or FTL pages.
Before
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags"%>After
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><!--[if !vml]--><!--[endif]-->
Many pages will require both the core and dojo tags. The sx: prefix is preferred for the Dojo tags.
Update the head tag
Review the new attributes of the new head <!--[if !vml]--><!--[endif]--> tag. You need to decide which values for the cache, compressed, parseContent and extraLocales attributes are appropriate for your application. These settings have major performance implications.
Before:
<s:head theme="ajax"/>After:
<sx:head parseContent="true"/>Update all ajax themed tags
Some tags are available only in the Dojo plugin taglib. It will be immediately obvious from your IDE that these tags need to change to the sx: prefix.
Some tags are available in both the core and Dojo plugin taglibs. Any tag that uses the ajax theme needs to be changed to the sx: prefix.
Before:
<s:url id="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><s:div id="jobStatus" theme="ajax" href="%{jobStatus}" updateFreq="5000" indicator="indicator"></s:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/>After:
<s:url var="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><sx:div id="jobStatus" href="%{#jobStatus}" updateFreq="5000" autoStart="true" indicator="indicator"></sx:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/><!--[if !vml]--><!--[endif]-->
If you forget to migrate a tag reference from the core to the dojo plugin you will receive an exception similar to the one below:
2008-04-19 14:32:30,475 ERROR [http-8443-Processor23] [[jsp]] Servlet.service() for servlet jsp threw exceptionorg.apache.jasper.JasperException: No tag "datetimepicker" defined in tag library imported with prefix "s"
Check inline javascript
If your ajax html results contain inline javascript that needs to be executed after updating the DOM, ensure your ajax tags set executeScripts="true" and separateScripts="true". These attributes instruct the widget to search for javascript in the result,
extract it, update the DOM with the result and then execute the javascript.
eg. The following bind will execute scripts within the result when the Submit button is pressed
<s:submit value="Submit" id="submit3" /><sx:bind targets="div1" highlightColor="#ffffcc" highlightDuration="500" sources="submit3"events="onclick" href="%{#fragment3Url}" errorNotifyTopics="/error" executeScripts="true"separateScripts="true"/>Check inline widgets
If your ajax html results include dojo widgets, ensure the head tag's parseContent attribute is true. This instructs dojo to parse the ajax responses for widgets. Note that Struts2.0 always enabled this feature and it could not be turned off. Struts2.1 disables this feature and allows it to be turned on as there is a significant performance impact.
Convert EL expressions to OGNL
Struts2.1 tags do not allow evaluation of JSP EL within their attributes. Instead, Struts2 tags evaluate attribute values as OGNL. Allowing both expression languages within the same attribute opens major security vulnerabilities.
todo: how to convert
<!--[if !vml]--><!--[endif]-->
Forgetting to convert attributes to OGNL expressions will produce exceptions similar to the one below:
org.apache.jasper.JasperException: /example.jsp(8,6) According to TLD or attribute directive in tagfile, attribute value does not accept any expression
Reduce verbose logging
Struts 2.1 introduces more verbose logging than Struts 2.0. While extremely valuable, some users may find these annoying.
Missing Properties
This message states that the framework searched for a property in the value stack and failed to find it.
2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir]2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir]2008-04-19 14:21:08,177 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [templateDir]2008-04-19 14:21:08,178 WARN [http-8443-Processor25] [OgnlValueStack] Could not find property [org.apache.catalina.jsp_file]To hide these messages, turn off the WARN level logging for OgnlValueStack.
eg. Include a new limit category in your log4j.xml file (only log errors or worse):
<category name="com.opensymphony.xwork2.ognl.OgnlValueStack"> <priority value="error"/> </category>TextProvider missing keys
These messages state that the framework searched for text in a resource bundle and failed to find it.
2008-04-19 14:32:30,106 WARN [http-8443-Processor23] [TextProviderHelper] The first TextProvider in the ValueStack(package.Action) could not locate the message resource with key 'companyDetails.addressId'2008-04-19 14:32:30,107 WARN [http-8443-Processor23] [TextProviderHelper] The default value expression'companyDetails.addressId' evaluated to '10'To hide those messages, turn off the WARN level logging for TextProviderHelper.
eg. Include a new limit category in your log4j.xml file (only log errors or worse):
<category name="org.apache.struts2.util.TextProviderHelper"> <priority value="error"/> </category>
Update Unit Tests
There are two known major migration issues affecting user's unit tests.
The Configuration API now uses a Builder pattern
The ActionContext.getContext() method does not create a context on demand.
Review the Unit Tests included with Struts2 for recommended practices to setup the Configuration and context.
A quick fix for ActionContext.getContext() returning null :
ConfigurationManager configurationManager = new ConfigurationManager(); configurationManager.addContainerProvider(new XWorkConfigurationProvider()); Configuration config = configurationManager.getConfiguration(); Container container = config.getContainer(); ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); stack.getContext().put(ActionContext.CONTAINER, container); ActionContext.setContext(new ActionContext(stack.getContext())); assertNotNull(ActionContext.getContext());Trouble-shooting
The issues are listed in the same order as encountered after changing jars over from 2.0.x to 2.1.x. Noteworthy, the migration was done under the following setup: Fedora core 6, JDK 1.6.0_2 and Tomcat 6.0.10 running from MyEclipse plugin.
Result type "redirect-action" was renamed to "redirectAction":
SEVERE: Exception starting filter struts2Unable to load configuration. - action - file:/home/giaz/code/.metadata/.plugins/ com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:370)...Caused by: Error building results for action ScheduleJob in namespace - action - file:/home/giaz/code/.metadata/.plugins/ com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/WEB-INF/classes/struts.xml:39:98 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:372) ... 30 moreCaused by: There is no result type defined for type 'redirect-action' mapped with name 'success' - result - file:/home/giaz/code/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/webui/ WEB-INF/classes/struts.xml:40:50 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:616) ... 35 moreThe struts.xml before:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirect-action"> <param name="actionName">ListDisplayOptimizationJobStatus</param> </result> <result name="error" type="tiles">webui.requestFailed</result></action>To resolve this issue modify the struts.xml action definition to:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirectAction"> <param name="actionName">ListDisplayOptimizationJobStatus</param> </result> <result name="error" type="tiles">webui.requestFailed</result></action>or to:
<action name="ScheduleJob" class="com.sag.optimizer.ui.web.action.scheduler.ScheduleJobAction"> <result name="success" type="redirect">ListDisplayOptimizationJobStatus.action</result> <result name="error" type="tiles">webui.requestFailed</result></action>
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->Tiles 2.1.x plugin tiles.xml now requires DOCTYPE:
Problem Symptom:
Nov 22, 2007 11:38:11 AM org.apache.tiles.impl.BasicTilesContainer initINFO: Initializing Tiles2 container. . .Nov 22, 2007 11:38:11 AM org.apache.commons.digester.Digester errorSEVERE: Parse Error at line 2 column 19: Document is invalid: no grammar found.org.xml.sax.SAXParseException: Document is invalid: no grammar found. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)<!--[if !vml]--><!--[endif]-->
Reason for this
This is due to the fact that Tiles 2.0.5 now turns validation on as default.
The tiles.xml page before:
<?xml version="1.0" encoding="ISO-8859-1" ?><tiles-definitions/>To resolve the issue simply add:
<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://struts.apache.org/dtds/tiles-config_2_0.dtd"><tiles-definitions/><s:head theme="ajax"/> is obsolete, use a different theme:
Problem Symptom: Accessing any page that includes <s:head theme="ajax"/> produces the following error:
Nov 22, 2007 1:54:51 PM freemarker.log.JDK14LoggerFactory$JDK14Logger errorSEVERE:Expression parameters.parseContent is undefined on line 45, column 28 in template/ajax/head.ftl.The problematic instruction:----------==> ${parameters.parseContent?string} [on line 45, column 26 in template/ajax/head.ftl]----------Java backtrace for programmers:----------freemarker.core.InvalidReferenceException: Expression parameters.parseContent is undefined on line 45, column 28 in template/ajax/head.ftl. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124) at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)Resolution is to either remove the "<s:head theme="ajax"/>" or use a different theme e.g. <s:head theme="xhtml" />
Ajax UI tags were moved to the new dojo plugin, use /struts-dojo-tags taglib instead of (or in addition to) /struts-tags:
Problem Symptom: Accessing a page containing ajax UI tags through using the struts 2 taglib will produce the following error:
SEVERE: Servlet.service() for servlet jsp threw exceptionorg.apache.jasper.JasperException: /jsp/list/listOptimizationJobStatus.jsp(6,0) Attribute href invalid for tag div according to TLD at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)JSP before migration:
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="display" uri="http://displaytag.sf.net" %><%@ taglib prefix="s" uri="/struts-tags"%><s:url id="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><s:div id="jobStatus" theme="ajax" href="%{jobStatus}" updateFreq="5000" indicator="indicator"></s:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/>Resolution is to import and use struts-dojo-tags plugin instead:
<%@ page contentType="text/html; charset=UTF-8" language="java" %><%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><s:url var="jobStatus" includeParams="get" value="/RefreshOptimizationJobStatus.action" /><sx:div id="jobStatus" href="%{#jobStatus}" updateFreq="5000" autoStart="true" indicator="indicator"></sx:div><img id="indicator" src="img/indicator.gif" alt="Loading..." style="display:none"/><!--[if !vml]--><!--[endif]-->
Other Ajax UI tags were also moved to the dojo plugin
Note the use of remote div is now through the dojo plugin taglib sx. Other ui tags are also no longer available through the /struts-tags taglib but only through the /struts-dojo-tags taglib: datetimepicker and autocompleter.
User-defined converter (subclassing StrutsTypeConverter) will no longer be needed when using datetimepicker:
Problem Symptom: Your custom StrutsTypeConverter implementation does not longer work in version 2.1.x. In 2.0.x you needed to implement a custom StrutsTypeConverter e.g. StringToDateConverter to be able to parse and convert to Date the String posted from a datetimepicker control into the action. In version 2.0.x datetimepicker was posting a String formatted as specified in the "displayFormat" field e.g.
<%@ taglib prefix="s" uri="/struts-tags"%><s:datetimepicker label="Begin Date" name="beginDate" displayFormat="yyyy.MM.dd">In version 2.1.x datetimepicker will post a String Date in RFC 3339 format, so you can define your setter to receive a Date directly and avoid using converters for this purpose e.g.
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><sx:datetimepicker label="Begin Date" name="beginDate" displayFormat="yyyy.MM.dd">ActionMappingParams
Parameters set by the action mapping are not set/not available through ParameterAware (This change is only needed when going to 2.1.x (where x>0))
These are now only available if you use the new interceptor named "actionMappingParams".
发表评论
-
jsf 分页
2009-06-23 13:28 1028jsf 分页 -
用spring的bean来初始化一个serlvet 应该怎样去初始化呢
2009-03-14 00:41 1652最近做项目时,用spring的bean来初始化一个serlve ... -
ibatis与struts结合编程
2008-12-21 16:25 1078在该demo里,连接的是sqlserver 2005 的数据库 ... -
jfreechart的WEB图表开发_____个人测试
2008-12-21 16:13 1346demo.jad 是对demo包里的所有class文件进行j ... -
servlet学习手册
2008-12-19 22:11 2210第1章 servlet概论 ... -
java连接各种数据库
2008-12-19 22:02 1013一、jsp连接Oracle8/8i/9i数据库(用thin ...
相关推荐
-----------First Struts2.0 Project------------ 1.建立一个web Project; 2.导入struts2.0的核心包,注意全部导入全部的lib会引起错误; commons-fileupload-1.2.1.jar commons-io-1.3.2.jar freemarker-2.3.12.jar...
包含了struts2.0所需的5个jar包 commons-logging-1.1.jar freemarker-2.3.13.jar ognl-2.6.11.jar struts2-core-2.1.6.jar xwork-2.1.2.jar
struts2.0 要用到的 jar 包 commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,commons-logging-1.1.jar,freemarker-2.3.13.jar,ognl-2.6.11.jar,xwork-2.1.2.jar,struts2-core-2.1.6.jar 7个包 copy到WebRoot/WEB...
struts2与spring整合开发包,自己找到到了,想与大家共享;是不需要资源分的。献给那些需要的人。
一、v2.0 更新说明 新增: 完善讲师功能,从讲师入驻到讲师后台,形成一个业务闭环; 移动端 1.移动端增加讲师申请页,已是讲师的用户不显示申请按钮 2.增加移动端讲师管理,讲师可查看自己名下的专题课程、资料、...
基于Django2.1.2的OAuth2.0授权登录 大学生课程设计 基于Django2.1.2的OAuth2.0授权登录的课程设计 自己大二写的课程设计
Java EE开发框架,struts2.1.2开发包,里面包含了struts框架的所有jar包
spring版本有2.0,2.5的,hibernate版本较多些至3.2,首先选版本就选择最优的,struts2没的选只有2.1.6版的,所以先导入struts2支持,然后是spring选的是2.0,问题就出在struts2中spring的插件上了,没有从MyEclipse...
struts2-core-2.1.2.jar, struts2-core-2.1.6.jar, struts2-core-2.1.8.1-sources.jar, struts2-core-2.1.8.1.jar, struts2-core-2.1.8.jar, struts2-core-2.2.1.1.jar, struts2-core-2.2.1.jar, struts2-core-2.2....
struts2-dojo-plugin-2.1.2.jar CSDN大多下载不了,所以上传!
Struts 2 Core 2.1.2 API Struts 2最新API
struts2.1.2版本的所有的jar包
这是Struts2.1.2的所有类库,里面我还放了一个.war的包。解压后可以看到基本的配置与文件分布
简单的struts2+portlet2 Example 依赖已打包
struts-2.1.2-lib.zip库文件
xwork-2.1.2-all.zip的源码,用于struts2.0学习
struts-2.1.2-src.zip
使用compass+lucene实现简单的全文...里面整合了spring2.5、hibernate3.2、struts2.0,是对数据库进行全文检索的一个非常好的demo的所有jar包组合! 对研究基于数据库检索的java开源搜索引擎的朋友有很大的参考价值
struts2-dojo-plugin-2.3.15.3.jar.zip