Tiles 与 Struts 2 注释的集成 [英] Tiles Integration with Struts 2 Annotation

查看:33
本文介绍了Tiles 与 Struts 2 注释的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将 Tiles 与基于 Struts 2 注释的操作集成,但它无法正常工作.

I have been trying to integrate Tiles with Struts 2 annotation based action but it's not working correctly.

由于我没有 struts-config.xml,并且在网络上可用的每个教程中,他们都使用 struts-config.xml 来引用它.

As I don't have struts-config.xml and in every tutorial available at web they are referencing it with struts-config.xml.

首先,是否可以将基于注解的 struts 操作与磁贴集成在一起.如果是,那么如何?

First is it possible to integrate annotation based struts action with tiles. If yes then how?

@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 错误

This is what my code is but it always gives me error in MyEclipse at TilesResult.class that

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>

谁能帮我在基于注释的动作中添加图块

Can anyone help me how to add tiles in annotation based actions

我使用 type="tiles" 而不是 type=TilesResult.class 然后它给了我以下异常

I used type="tiles" instead of type=TilesResult.class then it has given me below exception

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)

推荐答案

试试这些:

  1. 使用 type="tiles" 而不是 type="TilesResult.class"

使用您的目标磁贴定义,location="tiles-definition-name",而不是 JSP 页面,location="/jsp/userLogin.jsp",在您的结果位置

Use your target tile definition, location="tiles-definition-name", instead of JSP page, location="/jsp/userLogin.jsp", in your result location

在您的 web.xml 中有以下内容:

Have following in your web.xml:

<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name><param-value>/WEB-INF/tiles.xml</param-value></context-param><监听器><listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class></listener>

在您的 struts.xml 中包含以下内容(如果您单独使用注释而不使用 struts.xml,那么您必须为此创建一个最少的注释因为没有可用于定义自定义结果类型的注释)

Have following in your 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)

<代码><constant name="struts.convention.default.parent.package" value="codeoftheday.blogspot.com"/><package name="codeoftheday.blogspot.com" extends="struts-default"><结果类型><result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/></结果类型></包></struts>

注意:我在这里写了一篇关于这个问题的详细博客文章 - Maven、Struts2 注释和 Tiles 集成示例,通过约定/代码隐藏/使用 Eclipse IDE 的零配置插件

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆