Struts 2无法使用bean:message

时间:2013-02-08 05:25:10

标签: java jsp struts2 resources javabeans

我正在尝试使用bean来显示预定义的消息,我创建了以下文件,但是当我输入< me时,它会遇到以下错误:自动代码生成器未显示<message - resources>标记!!!!

org.apache.jasper.JasperException: The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

root cause

The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.

struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts-config>
    <!-- Configuration for the default package. -->
      <message-resources parameter="com/myapp/struts/messages"/>   
    <package name="default" extends="struts-default">

        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>
        <action name="register">
            <result type="tiles">register</result>
        </action>
    </package>

</struts-config>

register.jsp

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

    <div id="Header">
        <bean:message key="welcome.loggedin"/>
    </div>

messages.properties

# -- welcome --
welcome.loggedin=You are logged in.
welcome.heading=Struts Applications in Netbeans!
welcome.message=It's easy to create Struts applications with NetBeans.

我想问题是我的jar文件

commons-digester-1.8.1.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.1.jar
commons-logging-1.1.jar
displaytag-1.2.jar
displaytag-export-poi-1.2.jar
displaytag-portlet-1.2.jar
freemarker-2.3.13.jar
jdom-1.1.jar
jstl-1.2.jar
junit-3.8.1.jar
ognl-2.6.11.jar
pagertag.jar
sqlite-jdbc-3.7.2.jar
struts2-convention-plugin-2.1.6.jar
struts2-core-2.1.6.jar
struts2-dojo-plugin-2.1.2.jar
struts2-tiles-plugin-2.1.6.jar
tiles-api-2.1.2.jar
tiles-compat-2.1.2.jar
tiles-core-2.1.2.jar
tiles-jsp-2.1.2.jar
tiles-servlet-2.1.2.jar
struts-taglib-1.3.10.jar
xwork-2.1.2.jar

2 个答案:

答案 0 :(得分:1)

您在Struts 2应用程序中使用Struts 1标记。别。 Struts 1和Struts 2是两个完全不同的Web框架。

这是Struts2 documentation page about i18n

答案 1 :(得分:1)

<bean:message key=标记是Struts1标记,在Struts2中它被<s:text name=替换。除非你没有足够的理由来运行这两个框架,否则你不应该使用Struts1标签。