Struts (Java),更改采用输入参数=页面的操作的前向名称不允许我以新名称访问该页面
我对 Struts 还很陌生(对于当前雇主的遗留项目),在本例中我使用的是 Struts 1,所以不确定这是否重要。
我正在尝试编辑一个包含大量前锋的动作,但为了简单起见,我只包含了一个。该特定转发仅映射到静态 JSP,通常无需登录应用程序即可访问。
因此,通常可以在以下位置访问此页面(假设我在本地运行此页面):
https://localhost/sc.do?page=download
转发设置为:
<forward name="download" path=".downloadPage"/>
现在我尝试做的就是将名称 download
更改为其他名称(在下面的转发中),例如 downloadtest
,我确保重建它等并重新启动,现在我无法在
https://localhost/sc.do?page=download
访问它,但也没有我可以访问该页面吗: https://localhost/sc.do?page=downloadtest
我真的很困惑配置文件中还有什么会阻止它工作,我一直在阅读教程和我的理解这应该有效。非常感谢任何建议。
<action path="/sc"
type="com.somecompany.wa.actions.PageDispatchAction"
name="scAdminForm"
parameter="page">
<set-property property="secure" value="true"/>
<forward name="downloadtest" path=".downloadPage"/>
</action>
这是 com.somecompany.wa.actions.PageDispatchAction 类:
public class PageDispatchAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionContext context = new ActionContext(mapping, form, request, response);
Command command = new CheckPageSecurityCommand();
boolean stop = command.execute(context);
if (stop) {
return null;
} else {
return (ActionForward) context.get("forward");
}
}
// redirects control to logout page
// calls to this method should be followed by return null or end of method.
protected void redirectToLogout(HttpServletRequest request, HttpServletResponse response) throws Exception {
ServletWebContext context = new ServletWebContext(request.getSession(true).getServletContext(), request, response);
Command command = new RedirectToLogoutCommand();
command.execute(context);
}
}
I'm still fairly new to Struts (for a legacy project for current employer), in this case I am using Struts 1 so not sure if that matters.
I am trying to edit an action that has a bunch of forwards but for simplicity I have just included one. This particular forward just maps to a static JSP and can normally be accessed without having to login to the application.
So normally this page is accessed at (assuming I'm running this locally):
https://localhost/sc.do?page=download
The forward is set as:
<forward name="download" path=".downloadPage"/>
Now all I tried doing was changing the name download
to something else (in the forward below), such as downloadtest
, I made sure to rebuild it, etc and relaunched, now I cannot access it at
https://localhost/sc.do?page=download
but neither can I access the page at: https://localhost/sc.do?page=downloadtest
I'm really confused as to what else there would be in a configuration file that would prevent this from working, I have been reading tutorials and from my understanding this should work. Any advice is greatly appreciated.
<action path="/sc"
type="com.somecompany.wa.actions.PageDispatchAction"
name="scAdminForm"
parameter="page">
<set-property property="secure" value="true"/>
<forward name="downloadtest" path=".downloadPage"/>
</action>
This is the com.somecompany.wa.actions.PageDispatchAction class:
public class PageDispatchAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionContext context = new ActionContext(mapping, form, request, response);
Command command = new CheckPageSecurityCommand();
boolean stop = command.execute(context);
if (stop) {
return null;
} else {
return (ActionForward) context.get("forward");
}
}
// redirects control to logout page
// calls to this method should be followed by return null or end of method.
protected void redirectToLogout(HttpServletRequest request, HttpServletResponse response) throws Exception {
ServletWebContext context = new ServletWebContext(request.getSession(true).getServletContext(), request, response);
Command command = new RedirectToLogoutCommand();
command.execute(context);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我更熟悉 Struts 1.2,这里看起来像 Struts 1.3,但我惊讶地发现
PageDispatchAction
没有扩展DispatchAction
而不是行动
。通常,当您在struts-config.xml
中定义action
的parameter
属性时,type
指的是DispatchAction
的子类。这表明请求中提供的任何page
值都将按照此处定义的方式映射到同名操作中的方法。因此,page=download
将映射到PageDispatchAction
中的download
方法。不管怎样,我不确定你这里的内容是如何工作的,因为在我看来,返回似乎正在寻找一个名为forward
的ActionForward
。也许这是我对 Struts 1.2 的偏见,而 1.3 的工作方式有所不同。没有把握。I'm more familiar with Struts 1.2 and what you have here looks like Struts 1.3, but I was surprised to see that
PageDispatchAction
didn't extendDispatchAction
instead ofAction
. Typically, when you define theparameter
attribute of anaction
instruts-config.xml
thetype
refers to a subclass ofDispatchAction
. This indicates that whatever value forpage
is supplied in the request would map to a method in the action of the same name with the way things are defined here. Sopage=download
would map to adownload
method inPageDispatchAction
. Anyway, I'm not sure how what you have here is working since to my eye it looks like the return is looking for anActionForward
calledforward
. Perhaps it is my Struts 1.2 bias though and 1.3 works differently. Not sure.