javax.servlet.ServletException:javax.servlet.jsp.JspException:找不到bean

时间:2014-04-17 12:43:18

标签: java jsp servlets struts

我正在尝试构建一个简单的struts应用程序,我尝试使用表单bean将java操作中的字符串值打印到jsp。

first.jsp

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>

    <body>
        Welcome!!!!!!!!

        <bean:write name="myForm" property="st"/>
    </body>
</html>

的struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
        "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

    <form-beans>
        <form-bean name="myForm" type="com.myForm" />
    </form-beans>

    <action-mappings>
        <action path="/view" name="myForm" type="com.myAction" validate="false">
                <forward name="success" path="/first" />
        </action>
        <action path="/view"
                forward="/view.jsp"/>
        <action path="/first"
                forward="/first.jsp" />
    </action-mappings>
</struts-config>

myForm.java

package com;

public class myForm extends org.apache.struts.action.ActionForm {

    private String st;

    public String getSt()
    {
        return st;
    }

    public void setSt(String st)
    {
        this.st=st;
    }

    public myForm(String st)
    {
        this.st=st;
    }
}

myAction.java

package com;

import java.io.IOException;
import javax.servlet.ServletException;
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.myForm;

public class myAction extends org.apache.struts.action.Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

        myForm form1=(myForm) form;

        String s="Karthikeyan";

        System.out.println("Hello "+s);

        form1.setSt(s);

        //RequestDispatcher reqDispatcher = getRequestDispatcher("view.jsp");
        //reqDispatcher.forward(request,response);




        return (mapping.findForward("success"));
    }
}

这些是重要的文件,因此我没有添加文件web.xml和view.jsp,因为我确定错误与我发布的文件代码有关。 我得到的错误是:

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "myForm" in any scope

我不知道为什么我遇到错误,因为我在struts-config.xml中定义它。请帮忙。

0 个答案:

没有答案