使用 Stripes 将 JSP 文件移动到 WEB-INF 目录时出错
我有以下 Stripes 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 目录中?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的理解如下:您的
WelcomeActionBean
不在由NameBasedActionResolver
(阅读javadoc)所以它实际上是映射到/myapp/Welcome.action
(如错误消息中所述)。因此,当您请求
/Welcome.action
时,没有任何现有ActionBean
绑定到该 URL,解析器会回退到/welcome.jsp
> (再次参见NameBasedActionResolver
javadoc)。当您将 JSP 移动到/WEB-INF/jsp
下时,您就会运气不佳,一切都会失败。要解决此问题,可以:
访问“正确”(在当前状态下)URL 绑定,即
/myapp/Welcome.action
或者,如果您希望 ActionBean 按照约定绑定到
/Welcome.action
,请将其移动到由NameBasedActionResolver
,例如action
:或者将
@UrlBinding
添加到您的操作中以显式配置绑定:My understanding is the following: your
WelcomeActionBean
in not in a package ([web, www, stripes, action]) automagically handled by theNameBasedActionResolver
(read the javadoc) so it is actually mapped to/myapp/Welcome.action
(as stated in the error message).So, when you request
/Welcome.action
, there isn't any existingActionBean
bound to that URL and the resolver fallbacks to/welcome.jsp
(again, see theNameBasedActionResolver
javadoc). And when you move your JSP under/WEB-INF/jsp
, well, you run out of luck and everything just fails.To solve this, either:
Access the "right" (in the current state) URL binding i.e.
/myapp/Welcome.action
Or, if you want your ActionBean to be bound to
/Welcome.action
by the conventions, move it in a package handled by theNameBasedActionResolver
, e.g.action
:Or add a
@UrlBinding
to your action to configure the binding explicitly:WEB-INF
是一个特殊目录,客户端无法访问其内容。 (这是有道理的 - 您不希望客户端能够下载您的web.xml
或.class
文件。)您需要将 JSP 文件移到外部
WEB-INF
。WEB-INF
is a special directory, and its contents aren't accessible to the client. (It makes sense - you wouldn't want the client to be able to download yourweb.xml
or your.class
files.)You need to move the JSP files outside of
WEB-INF
.