找不到ActionMappings或ActionFormBeans集合?

时间:2011-04-13 18:35:31

标签: jsp struts jsp-tags struts-1 struts-config

你好男人的 我在struts中运行程序时是struts的新手,我得到了这样的错误....

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:531)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:901)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:830)
    org.apache.jsp.insert_jsp._jspService(insert_jsp.java:83)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
    org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:798)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
    org.apache.jsp.insert_jsp._jspx_meth_html_005fform_005f0(insert_jsp.java:136)
    org.apache.jsp.insert_jsp._jspx_meth_html_005fhtml_005f0(insert_jsp.java:106)
    org.apache.jsp.insert_jsp._jspService(insert_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

mycode就像这样...... InsertModel.java

package com.cac.struts;
import java.sql.*;
public class InsertModel
{
    public boolean insert(String name,String branch,int regd)
    {
        boolean b=false;
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:mohit","system","rock");
            PreparedStatement ps=con.prepareStatement("insert into emp values(?,?,?)");
            ps.setString(1,name);
            ps.setString(2,branch);
            ps.setInt(3,regd);
            int k=ps.executeUpdate();
            if(k>0)
                b=true;
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return b;
    }
}

InsertForm.java

package com.cac.struts;
import org.apache.struts.action.ActionForm;
public class InsertForm extends ActionForm
{
    private int regd;
    private String name;
    private String branch;
    public void setRegd(int r)
    {
        regd=r;
    }
    public int getRegd()
    {
        return regd;
    }
    public void setName(String name)
    {
        this.name=name;
    }
    public String getName()
    {
        return name;
    }
    public void setBranch(String branch)
    {
        this.branch=branch;
    }
    public String getBranch()
    {
        return branch;
    }
}

InsertAction.java

package com.cac.struts;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class InsertAction extends Action
{
    public ActionForward execute(ActionMapping am,ActionForm af,HttpServletRequest hreq,HttpServletResponse hres) throws Exception
    {
        String key="failure";
        InsertForm iif=(InsertForm)af;
        int regd=iif.getRegd();
        String name=iif.getName();
        String branch=iif.getBranch();
        InsertModel im=new InsertModel();
        boolean b=im.insert(name,branch,regd);
        if(b)
        {
            key="success";
        }
        ActionForward af1=am.findForward(key);
        return af1;
    }
}

的web.xml

<web-app>
    <servlet>
        <servlet-name>one</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>one</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
</web-app>

支柱-config.html

<struts-config>
    <form-beans>
        <form-bean name="insertForm" type="com.cac.struts.InsertForm">
    </form-beans>
    <action-mappings>
        <action path="/insert" type="com.cac.struts.InsertAction" name="insertForm">
            <forward name="success" path="/success.jsp">
            <forward name="failure" path="/failure.jsp">
        </action>
    </action-mappings>
</struts-config>

insert.jsp

&lt;%@ taglib uri =“/ WEB-INF / struts-html.tld”prefix =“html”%&gt;

<html:html>
    <body bgcolor="yellow">
    <center>
        <h1>Student Application</h1>
        <html:form action="insert" method="post">
            regd<html:text property="regd"/><br><br>
            name<html:text property="name"/><br><br>
            branch<html:text property="branch"/><br><br>
        <html:submit>insert</html:submit>
        </html:form>
    </center>
    </body>
</html:html>

另外我还使用了lib中的所有jar文件和struts-html.tld。 请...请帮助我...... !!

2 个答案:

答案 0 :(得分:0)

&LT; action path =“/ insert”type =“com.cac.struts.InsertAction”name =“insertForm”scope =“request”validate =“false”input =“/ insert.jsp”&gt;

答案 1 :(得分:0)

你可能错过了其中一个罐子:

公地digester.jar
公地beanutils.jar
的struts.jar

将它们添加到项目中应解决您的问题