Struts2 - 如果我调用 Action-Bean2,如何从 Action-Bean1 调用方法?
我做了一种名为 ProfileSelector 的操作,它是通过一些 ajax 调用(通过使用 JQuery 库)加载的。
这是代码:(
// BEAN
public class ProfileSelector extends ActionSupport implements ParameterAware {
private String profilePage;
private Map<String, String[]> parameters;
@Override
public String execute() throws Exception {
profilePage=getParameterValue("profilePage");
return profilePage;
}
public String getParameterValue(String param) {
if (getParameters().get(param)==null) return "main";
return ((String[])getParameters().get(param))[0];
}
public Map<String, String[]> getParameters() { return parameters; }
public void setParameters(Map<String, String[]> maps) { this.parameters=maps; }
public String getProfilePage() { return profilePage; }
public void setProfilePage(String profilePage) { this.profilePage=profilePage; }
}
// STRUTS.XML
<action name="profile" class="model.ProfileSelector" >
<result name="main">/profile/profile_main.jsp</result>
<result name="edit">/profile/profile_edit.jsp</result>
<result name="editConfirm">/profile/profile_edit.jsp</result>
<result name="pm">/profile/profile_pm.jsp</result>
<result name="articles">/profile/profile_articles.jsp</result>
</action>
// PAGE.JSP
<c:choose>
<c:when test="${profilePage=='edit'}">
<s:div>
EDIT
<s:url id="edit" action="profile.action"><s:param name="profilePage">editConfirm</s:param></s:url>
<sj:submit href="%{edit}" targets="profileContent" value="Edit" />
</s:div>
</c:when>
<c:when test="${profilePage=='editConfirm'}">
// HERE I NEED TO LOAD A VALUE FROM ANOTHER BEAN-ACTION, not the profile one
</c:when>
</c:choose>
在代码中)查看这里我需要从另一个BEAN-ACTION加载一个值,而不是配置文件:在这里我需要加载(例如)一个方法来自另一个 Action-Bean。 (示例
我该怎么做?我认为 Struts 是不可能的,因为我一次只能调用 1 个操作。那么,拦截器?我需要改变我的应用程序的整个结构吗?
请告诉我。
I making a sort of action called ProfileSelector, that is loaded trought some ajax call (by using JQuery library).
This is the code :
// BEAN
public class ProfileSelector extends ActionSupport implements ParameterAware {
private String profilePage;
private Map<String, String[]> parameters;
@Override
public String execute() throws Exception {
profilePage=getParameterValue("profilePage");
return profilePage;
}
public String getParameterValue(String param) {
if (getParameters().get(param)==null) return "main";
return ((String[])getParameters().get(param))[0];
}
public Map<String, String[]> getParameters() { return parameters; }
public void setParameters(Map<String, String[]> maps) { this.parameters=maps; }
public String getProfilePage() { return profilePage; }
public void setProfilePage(String profilePage) { this.profilePage=profilePage; }
}
// STRUTS.XML
<action name="profile" class="model.ProfileSelector" >
<result name="main">/profile/profile_main.jsp</result>
<result name="edit">/profile/profile_edit.jsp</result>
<result name="editConfirm">/profile/profile_edit.jsp</result>
<result name="pm">/profile/profile_pm.jsp</result>
<result name="articles">/profile/profile_articles.jsp</result>
</action>
// PAGE.JSP
<c:choose>
<c:when test="${profilePage=='edit'}">
<s:div>
EDIT
<s:url id="edit" action="profile.action"><s:param name="profilePage">editConfirm</s:param></s:url>
<sj:submit href="%{edit}" targets="profileContent" value="Edit" />
</s:div>
</c:when>
<c:when test="${profilePage=='editConfirm'}">
// HERE I NEED TO LOAD A VALUE FROM ANOTHER BEAN-ACTION, not the profile one
</c:when>
</c:choose>
Looks (in the code) at HERE I NEED TO LOAD A VALUE FROM ANOTHER BEAN-ACTION, not the profile one : is here that i need to load (for example) a method from another Action-Bean. (example <s:property value="someMethod" />
How can I do it? I think is impossible with Struts, because I can call only 1 action at time. So, Interceptors? I need to change my whole structure of the application?
Let me know. Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
// BEAN
//STRUTS.XML
//来自浏览器
P.S: 如果您熟悉 Struts 1,它的工作方式与 DispatchAction 类似。
// BEAN
//STRUTS.XML
//From browser
P.S: If you familiar with Struts 1, it work like DispatchAction.
这是不正确的,因为你永远不想为任何事情执行两个不同的操作。没有办法这样做。但是,您也许能够从 jsp 进行 ajax 调用并指向不同的操作并加载值。
There is something incorrect as you never want to goto 2 different actions for anything. There is no way to do so. However, you might be able to make an ajax call from the jsp and point to different action and load the value out.