从普通jsp页面调用struts2 jsp页面

从普通jsp页面调用struts2 jsp页面,jsp,struts2,struts,Jsp,Struts2,Struts,我有一个现有的普通jsp web应用程序。 根据客户要求,我需要创建一些带有下拉选择框的配置页面。我必须在Struts 2中创建这个页面。 我已经创建了一个struts页面,但无法从现有的应用程序调用这个struts2页面 我正在犯错误 The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are

我有一个现有的普通jsp web应用程序。 根据客户要求,我需要创建一些带有下拉选择框的配置页面。我必须在Struts 2中创建这个页面。 我已经创建了一个struts页面,但无法从现有的应用程序调用这个struts2页面

我正在犯错误

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]
    at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
    at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
    at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
    at jsp_servlet.__addprevdn._jsp__tag0(__addprevdn.java:112)
    at jsp_servlet.__addprevdn._jspService(__addprevdn.java:84)
    Truncated. see log file for complete stacktrace      

正如Umesh Awasthi所说,你不能那样做。你需要了解Struts2的一些基础知识

  • 首先,客户机请求通过Servlet容器,如Tomcat。然后,客户机请求通过一个链接系统,该系统涉及Servlet过滤器的三个组件
  • 在链接系统中,首先是
    HttpServletrequest
    通过
    ActionContextCleanUp
    过滤器。
    ActionContextCleanUp
    FilterDispatcher
    或一起工作,并允许与
    SiteMesh
    集成
  • 接下来,
    FilterDispatcher
    调用
    ActionMapper
    ,以确定哪个请求应该调用操作。它还处理执行操作,清理
    ActionContext
    ,并在Struts2的各个部分需要时提供静态内容,如JavaScript文件、CSS文件、HTML文件等
  • ActionMapper
    映射HTTP请求和操作调用请求,反之亦然。
    ActionMapper
    可能会返回一个动作,如果没有动作调用请求匹配,则可能会返回null值
  • ActionMapper
    希望调用某个操作时,通过与
    FilterDispatcher
    交互来调用
    ActionProxy
    ActionProxy
    获取Action类并调用适当的方法。此方法参考框架配置管理器,该管理器是从
    struts.xml
    文件初始化的
  • 读取
    struts.xml
    文件后,
    ActionProxy
    创建一个
    ActionInvocation
    &确定应该如何处理该操作
  • ActionProxy
    封装了如何获取操作,&
    ActionInvocation
    封装了调用请求时如何执行操作
  • 然后,
    ActionProxy
    ActionInvocation
    的帮助下调用拦截器。拦截器的主要任务是使用
    ActionInvocation
    调用操作
  • 一旦确定并执行了操作,则使用
    result
    组件生成结果。
    Result
    组件在
    struts.xml
    中映射的操作结果代码的帮助下从模板中查找数据该模板可能包含用于生成响应的JSP、FreeMarker
注意:早期struts2开发中使用了
FilterDispatcher
(org.apache.struts2.dispatcher.FilterDispatcher),自struts2.1.3以来,它已被弃用

如果您使用的是Struts版本>=2.1.3,则始终建议升级新的筛选器类–
StrutsPrepareAndExecuteFilter
(org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)

一些有用的链接


  • 希望这有帮助。

    你不能这样做,如果你绕过Struts2过滤器,框架还没有准备好为你服务,也没有标记,这也是对MVC不利的。请弄清楚如何使用struts2