zoukankan      html  css  js  c++  java
  • The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. 异常的处理方法

    异常信息: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.

    环境:tomcat 6.0  struts2.21

    web.xml的配置:

     

      <filter>

          <filter-name>struts2</filter-name>

          <filter-class>

              org.apache.struts2.dispatcher.ng.filter.StrutsPrepar                  eAndExecuteFilter

          </filter-class>

      </filter>

      <filter-mapping>

          <filter-name>struts2</filter-name>

          <url-pattern>*.action</url-pattern>

      </filter-mapping>

     

    默认是进行.action的过滤,以前都是使用freemarker作为显示端的,没出错,现在用jsp来显示点东西却出现了这个错误
    Test.jsp:

     

    <%@ page language="java" contentType="text/html; charset=UTF-8"

        pageEncoding="UTF-8"%>

    <%@taglib prefix="s" uri="/struts-tags" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>测试</title>

    </head>

        <body>

            <s:form action = "testAction.action">

                <s:textfield name = "stuMap['one'].stuNum" label = "第一个用户名"/>

                <s:password name = "stuMap['one'].password" label = "第一个密码"></s:password>

                <s:textfield name = "stuMap['two'].stuNum" label = "第二个用户名"/>

                <s:password name = "stuMap['two'].password" label = "第二个密码"></s:password>

                <s:submit name = "send" value = "提交" theme = "simple"></s:submit>

            </s:form>

        </body>

    </html>

     

    struts2的标签已经引入了,查询后归纳了以下几种方法:
    1.将web.xml下的struts2过滤器的过滤方式从.action改为/*;   不过这种方式自己感觉不太好,应该这样默认就将所有的进行了过滤,可能会对有些应用带来麻烦,例如

    fck的配置

    2. 修改Test.jsp 文件,不使用 struts 的标签

    3.就是在web.xml配置文件中再添加一个filter:

     

    <filter-mapping>

          <filter-name>struts2</filter-name>

          <url-pattern>*.jsp</url-pattern>

      </filter-mapping>

      <filter-mapping>

          <filter-name>struts2</filter-name>

          <url-pattern>*.action</url-pattern>

      </filter-mapping>

     

     

    操作:struts2中直接访问jsp
    异常: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.
    环境:struts2
    原因:如果想要在jsp文件中,采用 struts的tag,那么jsp必须是通过action跳转得到,也就是必须通过web.xml所配置的过滤器访问文件,否则会有异常。
    解决办法:
    配置通用操作:
    <action name="*">
         <result>/{1}.jsp</result>
      </action>
    以前访问jsp的操作换成action的操作:eg: 原来 test.jsp 先在test.do

    在使用struts的标签以后所有的请求都要经过filterdispatcher过滤来得到,jsp文件必须要经过action跳转得到,就是必须要通过web.xml中配置的过滤转发器来获得jsp文件。所以对jsp文件要配置其过滤映射/*.jsp.

  • 相关阅读:
    JMeter参数化及断言的使用
    JMeter基础概念
    postman关联
    postman参数化
    postman发送请求的简单操作
    postman的简单介绍及运用
    javascript小记五则:用JS写一个图片左右自由滚动的“跑马灯”效果
    javascript小记四则:用JS写一个滚动横条文字,可以根据需要进行修改;
    javascript小记三则:ASP.NET启动web调试,窗体自动放大的方法
    JavaScript小记二则:接上一节:用.net写Textbox控件关于数字的判断的另一则方法
  • 原文地址:https://www.cnblogs.com/moonfans/p/2985325.html
Copyright © 2011-2022 走看看