3

我有以下条纹 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 目录中?

4

2 回答 2

5

我的理解如下:您WelcomeActionBean不在包中([web,www,stripes,action])由NameBasedActionResolver(阅读javadoc)自动处理,因此它实际上被映射到/myapp/Welcome.action(如错误消息中所述)。

因此,当您请求时/Welcome.action,该 URL 没有任何现有ActionBean绑定,并且解析器回退到/welcome.jsp(再次参见 NameBasedActionResolverjavadoc)。当您将 JSP 移到 . 下/WEB-INF/jsp时,您运气不佳,一切都失败了。

为了解决这个问题,要么:

  • 访问“正确”(在当前状态下)的 URL 绑定,即/myapp/Welcome.action

  • 或者,如果您希望 ActionBean 受/Welcome.action约定约束,请将其移动到由 处理的包中NameBasedActionResolver,例如action

    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");
        }
    }
    
  • 或者在@UrlBinding您的操作中添加一个以显式配置绑定:

    package 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");
        }
    }
    
于 2010-02-12T09:14:31.433 回答
-1

WEB-INF是一个特殊目录,客户端无法访问其内容。(这是有道理的——您不希望客户端能够下载您web.xml或您的.class文件。)

您需要将 JSP 文件移到WEB-INF.

于 2010-02-12T08:27:23.973 回答