首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

“j2ee中struts架构:Struts-config.xml资料加了data-sources后就

2012-11-04 
“j2ee中struts架构:Struts-config.xml文件加了data-sources后就使用DBCP连接池操作数据库: 在struts-confi

“j2ee中struts架构:Struts-config.xml文件加了data-sources后就
使用DBCP连接池操作数据库:
在struts-config.xml中配置好了DBCP数据源,访问.do文件出错。
HTTP Status 404 - Servlet action is not available

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

<struts-config>
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" />
<set-property property="url" value="jdbc:mysql://127.0.0.1/demo" />
<set-property property="username" value="root" />
<set-property property="password" value="" />
<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="validationQuery" value="SELECT COUNT(*) FROM user" />
</data-source>
</data-sources>

<form-beans>
<form-bean name="loginForm"
type="com.demo.struts.forms.LoginForm">
</form-bean>
<form-bean name="registerForm"
type="com.demo.struts.forms.RegisterForm">
</form-bean>
</form-beans>

<global-exceptions />
<global-forwards>
<forward name="welcome" path="/welcome.do" />
<forward name="login" path="/login.do" />
</global-forwards>

<action-mappings>
<action path="/index" forward="/login.jsp" />
<action path="/welcome" forward="/welcome.jsp" />
<action path="/menu1" forward="/menu1.jsp" />
<action path="/menu2" forward="/menu2.jsp" />
<action path="/menu3" forward="/menu3.jsp" />
<action path="/menu4" forward="/menu4.jsp" />
<action path="/menu5" forward="/menu5.jsp" />
<action path="/menu6" forward="/menu6.jsp" />
<action path="/menu7" forward="/menu7.jsp" />
<action path="/menu8" forward="/menu8.jsp" />

<action path="/login" name="loginForm" scope="request"
type="com.demo.struts.actions.LoginAction" input="/login.jsp">
<forward name="success" path="/welcome.jsp" />
<forward name="failure" path="/login.jsp" />
</action>

<action path="/logout"
type="com.demo.struts.actions.LogoutAction">
<forward name="logout" path="/login.jsp" />
</action>

<action path="/register" parameter="method" name="registerForm"
scope="request" type="com.demo.struts.actions.RegisterAction"
input="/register.jsp">
<forward name="success" path="/login.jsp" />
<forward name="failure" path="/register.jsp" />
</action>

</action-mappings>

<message-resources parameter="com.demo.struts.resources.ApplicationResources" />

</struts-config>

去掉红色部分的data-sources就运行ok。找了快一天都没找出原因,郁闷......

今天又花了一天的时间,终于找到原因了:)
我仔细看了一下tomcat运行的日志:看到以下错误信息:
Communication failure during handshake. Is there a server running on 127.0.0.1:3306

解决办法:

1、把原来的mysql驱动换成mysql-connector-java-3.1.5-gamma-bin.jar,上传到网站根目录下的WEB-INF/lib下。
下载地址:http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.5-gamma.zip/from/http://mirrors.hpcf.upr.edu/mysql/

2、struts-config.xml文件中:
将“ <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" />”改成
“ <set-property property="driverClassName" value="com.mysql.jdbc.Driver" /> ”

3、重启tomcat

原文见:http://www.086php.com/index.php/struts-config/274

热点排行