|
Java学习者论坛
我用Spring+Struts+Hibernate做了一个练习,刚开始的时候没有问题,可过了一周左右就出现错误: HTTP Status 404 - Servlet action is not available
我的代码一直没有动过 为什么会这样呢?上网去查了一下 没有找到解决方法,请高手指点一下,谢谢!
我的 Web.xml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:sche2maLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
我的Struts-config.xml代码是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans>
<form bean name="testForm" type="com.struts.form.TestForm"></form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/show" attribute="testForm"
scope="request" parameter="show"
name="testForm"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="success" path="/jsp/show.jsp"></forward>
</action>
<action path="/update" attribute="testForm"
scope="request"
parameter="update"
name="testForm"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="success" path="/jsp/edit.jsp"></forward>
</action>
<action path="/save" attribute="testForm"
scope="request"
parameter="save"
name="testForm"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="success" path="/show.do" redirect="true"></forward>
</action>
<action path="/add" attribute="testForm"
scope="request"
parameter="add"
name="testForm"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="success" path="/show.do" redirect="true"></forward>
</action>
<action path="/delete" attribute="testForm"
scope="request"
parameter="delete"
name="testForm"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="success" path="/show.do" redirect="true"></forward>
</action>
<action path="/like" attribute="testForm"
scope="request"
parameter="like"
name="testForm"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="success" path="/jsp/likeShow.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
</struts-config>
我的Spring配置文件 applicationContext.xml 代码是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="Connection"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/job</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="Connection" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/entity/Test.hbm.xml</value>
<value>com/entity/Enterlogin.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- DAO层 -->
<bean id="UserDAO" class="com.dao.UserDAO">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 事物层 -->
<bean id="UserDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref local="UserDAO"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">ROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- service层 -->
<bean id="UserService" class="com.service.UserService">
<property name="dao">
<ref bean="UserDAOProxy"/>
</property>
</bean>
<!-- action层 -->
<bean class="com.struts.action.TestAction" name="/show">
<property name="uservice">
<ref bean="UserService"/>
</property>
</bean>
<bean class="com.struts.action.TestAction" name="/update">
<property name="uservice">
<ref bean="UserService"/>
</property>
</bean>
<bean class="com.struts.action.TestAction" name="/save">
<property name="uservice">
<ref bean="UserService"/>
</property>
</bean>
<bean class="com.struts.action.TestAction" name="/add">
<property name="uservice">
<ref bean="UserService"/>
</property>
</bean>
<bean class="com.struts.action.TestAction" name="/delete">
<property name="uservice">
<ref bean="UserService"/>
</property>
</bean>
<bean class="com.struts.action.TestAction" name2="/like">
<property name="uservice">
<ref bean="UserService"/>
</property>
</bean>
</beans>
我实在是找不到错误了,希望高手能指点一下!谢谢```
Java学习者论坛欢迎来到Java学习者论坛,转载请注明地址:http://www.javaxxz.com. |
|