struts 1:javax.servlet.jsp.JspException:找不到bean:" HelloWorldActionForm"在任何范围内

时间:2016-10-10 20:13:13

标签: struts-1

的index.jsp

<%@ page language =" java"的contentType =" text / html的;字符集= ISO-8859-1"     的pageEncoding =" ISO-8859-1"%GT;                        在这里插入标题          

<a href="<jsp:forward page="HelloWorld.jsp"/>">link</a>


</body>
</html>

HelloWorldAction.java

package com.test;

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;


public class HelloWorldAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HelloWorldActionForm helloWorldForm = (HelloWorldActionForm) form;
        helloWorldForm.setMessage("Hello World");
        return mapping.findForward("success");
    }


}

的struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<struts-config>
    <form-beans>
        <form-bean name="HelloWorldActionForm" type="com.test.HelloWorldActionForm"/>
    </form-beans>

    <global-forwards>
        <forward name="helloWorld" path="/helloWorld.do"/>
    </global-forwards>
    <action-mappings>
        <action input="/index.jsp" name="HelloWorldActionForm" path="/HelloWorld" scope="session" type="com.test.HelloWorldAction">
            <forward name="success" path="/helloWorld.jsp"/>
        </action>
    </action-mappings>
</struts-config>

HelloWorldActionForm.java

package com.test;

import org.apache.struts.action.ActionForm;

public class HelloWorldActionForm extends ActionForm {
    private static final long serialVersionUID = -473562596852452021L;

    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}

的helloWorld.jsp

<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<logic:present name="HelloWorldActionForm" property="message">
 <bean:write name="HelloWorldActionForm" property="message"/>
</logic:present>

</body>
</html>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>StrutsHelloWorld</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

0 个答案:

没有答案