我想用一些参数调用action类,但我能做到这一点。
请建议我在应用程序中传递带有映射struts.xml
文件的参数。
我在我的应用程序中使用Struts2框架。我的Struts文件操作映射如下:
<action name="createSHBehaviour/*" class="sadagi.pro.action.CreateSHBehaviourAction" >
<interceptor-ref name="accessRequired"/>
<interceptor-ref name="scope" />
<param name="param1">{1}</param>
<result name="success">views/createSHBehaviourView.jsp</result>
<result name="login" type="redirect">/</result>
</action>
用于调用操作类的和url:
http://localhost:8080/pro/createSHBehaviour/123
此处createSHBehaviour
是CreateSHBehaviourAction
类的方法:
public class CreateSHBehaviourAction extends ActionSupport implements
SessionAware,Parameterizable {
/**
*
*/
private static final long serialVersionUID = 1L;
private SessionMap<String, Object> sessionMap = null;
private Map<String, String> params = new HashMap<String, String>();
public String execute() {
System.out.println("param1 = " + this.params.get("param1"));
sessionMap = (SessionMap<String, Object>) ActionContext.getContext()
.getSession();
sessionMap.put("idSoftHumanS", "hhhh");
sessionMap.put("fix_behaviour_mode", true);
return Action.SUCCESS;
}
public void setSession(Map<String, Object> map) {
sessionMap = (SessionMap<String, Object>) map;
}
@Override
public void addParam(String key, String value) {
// TODO Auto-generated method stub
this.params.put(key, value);
}
@Override
public Map<String, String> getParams() {
// TODO Auto-generated method stub
return this.params;
}
@Override
public void setParams(Map<String, String> params) {
// TODO Auto-generated method stub
this.params = params;
}
}
我今天非常努力,请给我建议解决这个问题。 感谢
答案 0 :(得分:1)
使用ParameterAware
代替Parametrizable
或直接从动作上下文中获取参数。
Map<String, Object[]> parameters = ActionContext.getContext().getParameters();