将JSP文件移动到带条纹的WEB-INF目录时出错

问题描述 投票:3回答:2

我有以下条纹ActionBean:

package myapp;

import net.sourceforge.stripes.action.*;

public class WelcomeActionBean extends MyAppActionBean {
    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution("/welcome.jsp");
    }
}

当我在浏览器中加载/myapp/Welcome.action时,将显示welcome.jsp的内容。

但是,当我将welcome.jsp移至/WEB-INF/jsp/welcome.jsp并更改ForwardResolution参数以反映该更改时,即:

return new ForwardResolution("/WEB-INF/jsp/welcome.jsp");

加载/myapp/Welcome.action时出现以下错误:

net.sourceforge.stripes.exception.ActionBeanNotFoundException: Could not locate an ActionBean that is bound to the URL [/Welcome.action]. Commons reasons for this include mis-matched URLs and forgetting to implement ActionBean in your class. Registered ActionBeans are: {/controller/DefaultView.action=class net.sourceforge.stripes.controller.DefaultViewActionBean, /myapp/MyApp.action/=class myapp.MyAppActionBean, /myapp/Welcome.action/=class myapp.WelcomeActionBean, /controller/DefaultView.action/=class net.sourceforge.stripes.controller.DefaultViewActionBean, /myapp/MyApp.action=class myapp.MyAppActionBean, /myapp/Welcome.action=class myapp.WelcomeActionBean}
    net.sourceforge.stripes.controller.AnnotatedClassActionResolver.getActionBean(AnnotatedClassActionResolver.java:341)
    net.sourceforge.stripes.controller.NameBasedActionResolver.getActionBean(NameBasedActionResolver.java:264)
    net.sourceforge.stripes.controller.AnnotatedClassActionResolver.getActionBean(AnnotatedClassActionResolver.java:293)
    net.sourceforge.stripes.controller.DispatcherHelper$1.intercept(DispatcherHelper.java:106)
    net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158)
    net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
    net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
    net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
    net.sourceforge.stripes.controller.DispatcherHelper.resolveActionBean(DispatcherHelper.java:102)
    net.sourceforge.stripes.controller.DispatcherServlet.resolveActionBean(DispatcherServlet.java:238)
    net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:141)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:247)

为了将JSP文件存储在WEB-INF目录中是否需要执行任何特殊配置?

java web-applications stripes web-inf
2个回答
4
投票

我的理解如下:您的WelcomeActionBean不在包装中[[web,www,条纹,动作]),由NameBasedActionResolver自动读取(阅读javadoc),因此它实际上被映射到NameBasedActionResolver(如错误消息中所述)。

因此,当您请求/myapp/Welcome.action时,该URL上没有任何现有的/Welcome.action,解析器回退到ActionBean(再次请参见/welcome.jsp javadoc)。而且,当您将JSP移到NameBasedActionResolver下时,运气不佳,一切都会失败。

要解决此问题,请选择:

  • 访问“权限”(在当前状态下)URL绑定,即NameBasedActionResolver

  • 或者,如果您希望您的ActionBean通过约定绑定到/WEB-INF/jsp,请将其移动到/myapp/Welcome.action处理的包中,例如/Welcome.action

    NameBasedActionResolver
  • 或在操作中添加NameBasedActionResolver以显式配置绑定:

    action

-1
投票

package myapp.action; import net.sourceforge.stripes.action.*; public class WelcomeActionBean extends MyAppActionBean { @DefaultHandler public Resolution view() { return new ForwardResolution("/WEB-INF/jsp/welcome.jsp"); } } 是一个特殊目录,客户端无法访问其内容。 (这很有意义-您不希望客户端能够下载@UrlBindingpackage myapp; import net.sourceforge.stripes.action.*; @UrlBinding("/Welcome.action") public class WelcomeActionBean extends MyAppActionBean { @DefaultHandler public Resolution view() { return new ForwardResolution("/WEB-INF/jsp/welcome.jsp"); } } 文件。)

您需要将JSP文件移到WEB-INF之外。

© www.soinside.com 2019 - 2024. All rights reserved.