我想在使用 struts1 配置文件调用时传递一个实际值。我创建了一个具有以下属性的表单 bean
public class MyForm extends ActionForm {
private String task;
public String getTask() {
return task;
}
public void setTask(String task) {
this.task = task;
}
}
在 struts-config.xml 中,我定义了表单 bean 和操作,如下所示。
<form-bean name="myForm" type="demo.MyForm"></form-bean>
<action path="/myAction" name="myForm" type="demo.MyAction" scope="request">
<set-property value="view" property="task" />
<forward name="success" path="/result.jsp"></forward>
</action>
我尝试使用这些配置在 web sphere 6.1 中运行它,它给出了以下异常
Deregister the mbean because of uncaught init() exception thrown by servlet action: javax.servlet.UnavailableException: Parsing error processing resource path file:/D:/workspaces/j-space/myProject/Web Content/WEB-INF/struts-config.xml
at org.apache.struts.action.ActionServlet.handleConfigException(ActionServlet.java:761)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:744)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:689)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:356)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
....
我认为我遗漏了某些内容或以错误的方式使用了 set-property 标签。有人可以帮忙吗?
Struts 1.3 DTD http://struts.apache.org/1.3.10/struts-core/dtddoc/index.html says
当自定义子类时,“set-property”元素特别有用
与 , , , 或 一起使用
元素。
使用您想要包含的属性创建操作映射的子类
public class CustomActionMapping extends ActionMapping {
private String task;
public String getTask() {
return task;
}
public void setTask(String task) {
this.task = task;
}
}
配置自定义操作映射struts-config.xml
<action-mappings type="CustomActionMapping">
<action path="/myAction" name="myForm" type="demo.MyAction" scope="request">
<set-property value="view" property="task" />
<forward name="success" path="/result.jsp"></forward>
</action>
</action-mappings>
获取任务的值doGet/doPost
方法你的Action
class
CustomActionMapping cam = (CustomActionMapping) mapping;
String task = cam.getTask();
希望这对你有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)