Tiles与Struts 2注释的集成 [英] Tiles Integration with Struts 2 Annotation
问题描述
我一直在尝试将Tiles与基于Struts 2注释的动作集成在一起,但是无法正常工作.
由于我没有struts-config.xml
,因此在网络上提供的每个教程中,他们都使用struts-config.xml
进行引用.
首先可以将基于注释的Struts动作与图块集成在一起.如果是,那怎么办?
@Action(value="/login",results={@Result(name="success",location="/home",type=TilesResult.class),
@Result(name="login",location="/jsp/userLogin.jsp")})
public String execute() {
这就是我的代码,但它总是在MyEclipse的TilesResult.class
处给我错误
Type mismatch: cannot convert from Class<TilesResult> to String
我在pom中有依赖性:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.1.8</version>
</dependency>
任何人都可以帮助我如何在基于注释的操作中添加图块
我使用type="tiles"
而不是type=TilesResult.class
,但它给了我以下异常
Caused by: The Result type [tiles] which is defined in the Result annotation on the class [class com.actions.LoginAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [com.actions#convention-default#] - [unknown location]
at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:422)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:394)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:202)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:800)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:586)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:318)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
尝试以下方法:
-
使用
type="tiles"
代替type="TilesResult.class"
-
在结果位置中使用目标图块定义
location="tiles-definition-name"
而不是JSP页面location="/jsp/userLogin.jsp"
-
在
web.xml
中有以下内容:<context-param> <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name> <param-value>/WEB-INF/tiles.xml</param-value> </context-param> <listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener>
-
在
struts.xml
中有以下内容(如果您仅使用注释而没有使用struts.xml
,则必须为此创建一个最小的注释,因为没有可用的注释来定义自定义结果类型)><struts> <constant name="struts.convention.default.parent.package" value="codeoftheday.blogspot.com"/> <package name="codeoftheday.blogspot.com" extends="struts-default"> <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> </result-types> </package> </struts>
注意::我在此处就此问题撰写了详细的博客文章- This is what my code is but it always gives me error in MyEclipse at I have dependency in my pom: Can anyone help me how to add tiles in annotation based actions I used
Try these : Use Use your target tile definition, Have following in your Have following in your NOTE: I've written a detailed blog post here on this issue - Maven, Struts2 Annotations and Tiles Integration Example via Convention / Codebehind / Zero Config plugin using Eclipse IDE 这篇关于Tiles与Struts 2注释的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!TilesResult.class
that Type mismatch: cannot convert from Class<TilesResult> to String
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.1.8</version>
</dependency>
type="tiles"
instead of type=TilesResult.class
then it has given me below exceptionCaused by: The Result type [tiles] which is defined in the Result annotation on the class [class com.actions.LoginAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [com.actions#convention-default#] - [unknown location]
at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:422)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:394)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:202)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:800)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:586)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:318)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
type="tiles"
instead of type="TilesResult.class"
location="tiles-definition-name"
, instead of JSP page, location="/jsp/userLogin.jsp"
, in your result locationweb.xml
:<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
struts.xml
(If you are using annotations alone and no struts.xml
, then you have to create a minimal one for this because there's no annotation available to define a custom result type)<struts>
<constant name="struts.convention.default.parent.package" value="codeoftheday.blogspot.com"/>
<package name="codeoftheday.blogspot.com" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
</package>
</struts>