我有以下条纹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目录中是否需要执行任何特殊配置?
我的理解如下:您的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
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");
}
}
文件。)
您需要将JSP文件移到WEB-INF
之外。