我刚开始使用 struts 来维护一个 struts 1.3 应用程序,在设置完所有内容并部署我的 hello world 应用程序后,我收到以下错误:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "helloWorldForm" in any scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.HelloWorld_jsp._jspService(HelloWorld_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
我的动作类如下所示:
package com.mkyong.common.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.mkyong.common.form.HelloWorldForm;
public class HelloWorldAction extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws Exception {
HelloWorldForm helloWorldForm = (HelloWorldForm) form;
helloWorldForm.setMessage("Hello World! Struts");
return mapping.findForward("success");
}
}
我的表单类是这样的:
package com.mkyong.common.form;
import org.apache.struts.action.ActionForm;
public class HelloWorldForm extends ActionForm{
String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
struts-config.xml 像这样:
<form-beans>
<form-bean name="helloWorldForm"
type="com.mkyong.common.form.HelloWorldForm"/>
</form-beans>
<action-mappings>
<action path="/helloWorld"
type="com.mkyong.common.action.HelloWorldAction"
name="helloWorldForm">
<forward name="success" path="/HelloWorld.jsp"/>
</action>
</action-mappings>
HelloWorld.jsp 像这样:
<html>
<head>
</head>
<body>
<h1><bean:write name="helloWorldForm" property="message" />
</h1>
</body>
</html>
老实说,我只是想在此基础上再接再厉,但无法让它发挥作用,并想知道是否有人能指出我正确的方向。
非常感谢任何帮助和建议。