在struts2中找不到Struts调度程序

时间:2011-12-27 16:27:04

标签: java struts2 glassfish-3

最初我的jsp页面以正确的方式显示当我点击提交按钮时它显示sql库的类找不到异常然后我添加mysql库它不是showng jsp页面并且给出异常

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]

根本原因

  

找不到Struts调度程序。这通常是由于使用没有关联过滤器的Struts标记引起的。 Struts标记仅在请求通过其servlet过滤器时可用,该过滤器初始化此标记所需的Struts调度程序。

请帮我解决此问题

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
         id="WebApp_ID" 
         version="2.5">

  <display-name>Struts2Example17</display-name>
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

此错误也即将来临

SEVERE: log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.
SEVERE: log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: WebModule[/Struts2Example17]PWC1270: Exception starting filter struts2

errortrace

SEVERE: log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.
SEVERE: log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: WebModule[/Struts2Example17]PWC1270: Exception starting filter struts2
java.lang.InstantiationException
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:124)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4685)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5377)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2000)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1651)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:294)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:462)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232)
    at org.glassfish.deployment.admin.ReDeployCommand.execute(ReDeployCommand.java:126)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: Unable to load configuration. - bean - jar:file:/D:/strts2/Struts2Example17/build/web/WEB-INF/lib/struts2-dojo-plugin-2.1.8-sources.jar!/struts-plugin.xml:29:119
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:48)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:264)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:120)
    ... 47 more
Caused by: Unable to load bean: type:org.apache.struts2.views.TagLibrary class:org.apache.struts2.dojo.views.DojoTagLibrary - bean - jar:file:/D:/strts2/Struts2Example17/build/web/WEB-INF/lib/struts2-dojo-plugin-2.1.8-sources.jar!/struts-plugin.xml:29:119
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:222)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:165)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
    ... 53 more
Caused by: java.lang.ClassNotFoundException: org.apache.struts2.dojo.views.DojoTagLibrary
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1519)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1369)
    at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:146)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:193)
    ... 56 more

JSp文件

 <%-- 
        Document   : statusdonationjsp
        Created on : Dec 20, 2011, 10:34:09 PM
        Author     : bhavishya
    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib uri="/struts-tags" prefix="s"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Pending Donation </title>

        </head>
        <body>

        Search String
              <s:form action="FindPendingDonation">
        <s:textfield name="detail" label="Name" />
            <s:select name="amounttype" list="{'Cash','Cheque'}" label="Paymet type" id="type" onchange="displayBlock()" />
            <s:select name="status" list="{'Paid','Unpaid'}" label="Status(Cash)" />
        <s:textfield name="amount" label="Amount" />
            <s:textfield name="responsibleparty" label="Bank Name/Responsible party"  id="cash" />
            <s:textfield name="chequeno" lable ="Cheque NO" id="chequeno"/>

            <s:submit />
    </s:form>

        </body>
    </html>

7 个答案:

答案 0 :(得分:1)

根据讨论问题似乎是由于直接访问JSP页面而不是让Struts2 Dispatcher初始化请求处理周期并创建所需的值堆栈和其他参数。

Struts或基于MVC2的架构的最佳方式是,即使您的操作没有为您做任何工作,也要采取行动。

Struts2为此提供了开箱即用的功能,如果我们不在配置文件中提供任何动作类,Struts2将为我们动态创建一个Action类,并将返回SUCCESS作为结果。所以我们需要在我们的struts.xml文件

<action name="myaction">
  <result>/statusdonationjsp.jsp</result>
</action>

<强>更新

根据新的堆栈跟踪似乎在类路径中缺少dojo插件。请在类路径中包含struts2-dojo-plugin jar

答案 1 :(得分:1)

确保导入jar具有相同的struts2版本。因为

我收到了这个错误
  

Struts2的核 - 2.3.15.3.jar

  

的struts2-道场-插件-2.3.20

我能够通过使用版本2.3.15.3解决这个问题。

答案 2 :(得分:1)

我遇到了同样的问题。我的项目中有多个配置文件(其他文件包含在默认的struts.xml文件中)。 默认struts.xml中包含的文件名必须与&lt;包名称&gt;个人包括xmls,并且对于所有包含的文件不应该相同。在每个包含的xmls中给出正确的解决方案。 此链接非常有用 - http://www.codejava.net/frameworks/struts/splitting-modularizing-struts2-configuration-file

答案 3 :(得分:0)

此异常可能是由于1)在未定义的Web.xml过滤器中或2)服务器未查找Filter Dispatcher的web.xml。只需清理项目,清理服务器并重新启动服务器即可。它会起作用。

答案 4 :(得分:0)

我认为您的问题是您的web.xml文件。

只需将一个修改后的旧过滤器标签更改为新标签

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>

因此,它应该适用于此解决方案。但是,如果它不起作用,更好的方法是从此链接struts.war复制struts-blank.war文件。根据你的版本在这里我的意思是2.x版本,下载2.x一个rar文件并提取它&amp;在该副本struts-balnk.war并导入到您的ide for eg:eclipse在该目录结构的web内容下,将您的jsp文件100%复制它将起作用。

答案 5 :(得分:0)

请检查你的项目结构,即web.xml在WEB-INF文件夹下,所有视图都在webcontent文件夹下

答案 6 :(得分:0)

我也遇到了同样的问题,也尝试在上面的评论中提到改变jar文件,但没有解决问题。

最后,我发现在我的struts.xml文件中输入错误,action标记中的package标记。对于type标记的action属性,我已成功或错误。 实际上,必须有name属性而不是type。用于type用于重定向页面。

还在package标记中有namespace属性,我错误地输入了nameSpace, 由于这个原因,我面临“无法找到Struts调度员”。

但在我纠正错误之后它运行良好没有问题...所以只需检查你的struts.xml文件。