My Struts is 1.2.9,and tomcat is 5.5.15,and JDK is 1.5,I want to use Struts Datasource,my database is Microsoft Access 2000,and I have configured ODBC datasource in windows,when I run it, it raise follows error: type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available.
My code is follows: /*TestForm.java*/ *package* test;*import* org.apache.struts.action.*;*public* *class* TestForm *extends* ActionForm{} /*TestAction.java*/ *package* test;*import* java.io.*;*import* java.util.*;*import* java.sql.*;*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* javax.servlet.http.HttpServletRequest;*import* javax.servlet.http.HttpServletResponse; *public* *class* TestAction *extends* Action { *public* ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) *throws* Exception { System.out.println("ok"); javax.sql.DataSource dataSource; java.sql.Connection myConnection=*null*; *try*{ dataSource = getDataSource(request); myConnection = dataSource.getConnection(); Statement stmt = myConnection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM abc"); *while*(rs.next()){ System.out.print(rs.getString(1)); } rs.close(); stmt.close(); }*catch*(Exception e){ e.printStackTrace(); } *finally*{ *try* { myConnection.close(); } *catch* (SQLException e) { e.printStackTrace(); } } *return* *null*; }} /*Struts-config.xml*/ <?xml version="1.0" encoding="ISO-8859-1" ?> <!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> <data-sources> <data-source type="org.apache.commons.dbcp.BasicDataSource"> <set-property property="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver" /> <set-property property="url" value="jdbc:odbc:bb" /> <set-property property="username" value="administrator" /> <set-property property="password" value="123" /> <set-property property="maxActive" value="10" /> <set-property property="maxWait" value="5000" /> <set-property property="defaultAutoCommit" value="false" /> <set-property property="defaultReadOnly" value="false" /> <set-property property="abc" value="SELECT COUNT(*) FROM abc" /> </data-source> </data-sources> <form-beans> <form-bean name="Test" type="test.TestForm" /> </form-beans> <action-mappings> <action path="/Test" type="test.TestAction" name="Test" scope="request" validate="true" input="/test.jsp"/> </action-mappings> </struts-config> /*test.jsp*/ <html> <body> OK </body> </html> /*web.xml*/ <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <display-name>Struts Blank Application</display-name> <!-- 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/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>2</load-on-startup> </servlet> <!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- The Usual Welcome File List --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- Struts Tag Library Descriptors --> <taglib> <taglib-uri>/tags/struts-bean</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-html</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-logic</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-nested</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib> </web-app> When I run http://localhost:8080/Test.do,it raise following error: type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available. When I removes data-source from Struts-config.xml,it can run well.But when I add data-source into Struts-config.xml,it raise above erorr. I am puzzled with it very much! Anybody can tell me the reason and how to correct it? Thanks in advance!