1

这是我第一次使用 Struts,我构建了一个非常简单的程序
但我总是收到这个错误:(
我已经用谷歌搜索了 2 天,但我的类型肯定是正确的。这是我的代码:

web.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"        "http://java.sun.com/dtd/web-app_2_3.dtd">

    <web-app>
<filter>
    <filter-name>SetCharacterEncoding</filter-name>
    <filter-class>tw.com.whichone.filter.SetCharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>SetCharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>whichone</filter-name>
    <filter-class>tw.com.whichone.filter.CheckParameter</filter-class>
</filter>
<filter-mapping>
    <filter-name>whichone</filter-name>
    <url-pattern>*.whichone</url-pattern>
</filter-mapping>


<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>

        <param-value>/WEB-INF/conf/struts-config.xml</param-value>
    </init-param>
    <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
    </init-param>
    <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<!-- servlet-mapping -->

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>


<taglib>
    <taglib-uri>http://jakarta.apache.org/struts/tags-bean</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>http://jakarta.apache.org/struts/tags-logic</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>http://jakarta.apache.org/struts/tags-html</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>http://jakarta.apache.org/struts/tags-nested</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-nested.tld</taglib-location>
</taglib>

<taglib>
    <taglib-uri>http://jakarta.apache.org/struts/tags-tiles</taglib-uri>
    <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
</taglib>


struts-配置

    <?xml version="1.0" encoding="UTF-8"?>

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

    <struts-config>
<form-beans>
    <form-bean type="org.apache.struts.action.DynaActionForm"
        name="Store_Data">
        <form-property type="java.lang.String" name="one" />
        <form-property type="java.lang.String" name="StoreSeqNo" />
        <form-property type="java.lang.String" name="StoreName" />
        <form-property type="java.lang.String" name="StoreOwner" />
        <form-property type="java.lang.String" name="StoreAddress" />
        <form-property type="java.lang.String" name="StorePhone" />
        <form-property type="java.lang.String" name="StoreOpenDate" />

        <!-- "回首頁"連結清session專用變數 -->
        <form-property type="java.lang.String" name="CleanSession" />
    </form-bean>
</form-beans>

<global-forwards>
    <forward path="/success.html" name="Success" />
    <forward path="/error.html" name="Error" />
</global-forwards>

<action-mappings>
    <action path="/Store_Data_Parised" type="action.Store_Data_Parised"
        name="Store_Data" scope="request" validate="false" parameter="one">
    </action>
</action-mappings>


<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" />
<message-resources parameter="MessageResources" />
<plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"      
    />
    <set-property property="moduleAware" value="true" />
</plug-in>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"
        value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
    </struts-config>

索引.html

    <html>
    <head>
    <title>Test Page</title>
    </head>


    <body>
<form action="Store_Data_Parised.do?one=insert">
    <hr></hr>
    <h3>Add new store</h3>
    <table border="1" bordercolor="black">
        <tr>
            <td align="right">Store Name:&lt;/td>
            <td colspan="3"><input type="text" name="StoreName"
                maxlength="20" /></td>
        </tr>
        <tr>
    </table>

    <table border="1" bordercolor="black">
        <tr>
            <td align="right">Store Owner:&lt;/td>
            <td colspan="3"><input type="text" name="StoreOwner"
                maxlength="20" /></td>
        </tr>
        <tr>
    </table>

    <table border="1" bordercolor="black">
        <tr>
            <td align="right">Store Address:&lt;/td>
            <td colspan="3"><input type="text" name="StoreAddress"
                maxlength="20" /></td>
        </tr>
        <tr>
    </table>

    <table border="1" bordercolor="black">
        <tr>
            <td align="right">Store Phone:&lt;/td>
            <td colspan="3"><input type="text" name="StorePhone"
                maxlength="20" /></td>
        </tr>
        <tr>
    </table>

    <table border="1" bordercolor="black">
        <tr>
            <td align="right">OpenDate:&lt;/td>
            <td colspan="3"><input type="text" name="StoreOpenDate"
                maxlength="20" /></td>
        </tr>
        <tr>
    </table>
    <hr></hr>
    <input type="submit" value="Add" />

</form>
</body>
</html>

Store_Data_Parised.java

            public class Store_Data_Parised {

    public ActionForward insert(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    DynaActionForm Form = (DynaActionForm) form;
    String one = (String) Form.get("one");
    String StoreName = (String) Form.get("StoreName");
    String StoreOwner = (String) Form.get("StoreOwner");
    String StoreAddress = (String) Form.get("StoreAddress");
    String StorePhone = (String) Form.get("StorePhone");
    String StoreOpenDate = (String) Form.get("StoreOpenDate");

    try {

        Map criteria = new HashMap();
        criteria.put("StoreName", StoreName);
        criteria.put("StoreOwner", StoreOwner);
        criteria.put("StoreAddress", StoreAddress);
        criteria.put("StorePhone", StorePhone);
        criteria.put("StoreOpenDate", StoreOpenDate);

        Store_Data_handler.insert(criteria);

    } catch (Exception e) {

        return mapping.findForward("Error");
    }
    return mapping.findForward("Success");
    }

        }

4

1 回答 1

0

该类需要使用“Action”进行扩展,例如:public class Store_Data_Parised extends Action

于 2013-03-07T07:25:29.200 回答