环境是myeclipse+tomcat5.5+mysql; struts1.2+spring2.5+hibernate3.2
为了测试环境我只建立了一个简单的user表
输入后点击提交然后出现HTTP Status 404 - Servlet action is not available,
index.jsp页面
(用的是myeclipse自带的web browser)
<html>
<head>
<title>JSP for UserForm form</title>
</head>
<body>
<html:form action="/user">
password : <html:password property="password"/><br/>
username : <html:text property="username"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
<head>
<title>JSP for UserForm form</title>
</head>
<body>
<html:form action="/user">
password : <html:password property="password"/><br/>
username : <html:text property="username"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
当单击Submit后出现以下错误
1.ApplicationContext.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.gjt.mm.mysql.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/salemodel">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/saleModel/vo/User.hbm.xml</value></list>
</property></bean>
<bean id="userDAO" class="org.saleModel.dao.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userService" class="org.saleModel.service.UserService"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="userDAO">
<ref local="userDAO" />
</property>
</bean>
<bean name="/user" class="org.saleModel.struts.action.UserAction"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="userService">
<ref local="userService" />
</property>
</bean></beans>
<beans
xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.gjt.mm.mysql.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/salemodel">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/saleModel/vo/User.hbm.xml</value></list>
</property></bean>
<bean id="userDAO" class="org.saleModel.dao.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userService" class="org.saleModel.service.UserService"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="userDAO">
<ref local="userDAO" />
</property>
</bean>
<bean name="/user" class="org.saleModel.struts.action.UserAction"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="userService">
<ref local="userService" />
</property>
</bean></beans>
2.struts配置文件如下:
<?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">
<!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="userForm" type="org.saleModel.struts.form.UserForm" />//表单类
</form-beans>
<data-sources />
<form-beans >
<form-bean name="userForm" type="org.saleModel.struts.form.UserForm" />//表单类
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<global-forwards />
<action-mappings >
//........................................... action类的配置
<action
<action
attribute="userForm"
input="/jsp/index.jsp"
name="userForm"
path="/user"
scope="request"
>
<forward name="success" path="/jsp/success.jsp" />
<forward name="failure" path="/jsp/index.jsp" />
</action>
input="/jsp/index.jsp"
name="userForm"
path="/user"
scope="request"
>
<forward name="success" path="/jsp/success.jsp" />
<forward name="failure" path="/jsp/index.jsp" />
</action>
//......................................................................
</action-mappings>
//....................................... 控制器的配置
<controller>
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
</controller>
</controller>
//............................................
<message-resources parameter="org.saleModel.struts.ApplicationResources" />
<message-resources parameter="org.saleModel.struts.ApplicationResources" />
//.............................配置spring插件...................
<plug-in className="org.springframework.web.struts.contextLocationPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
</plug-in>
//............................
<plug-in className="org.springframework.web.struts.contextLocationPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
</plug-in>
//............................
</struts-config>
3.web.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.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>2</load-on-startup>
</servlet>
<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>2</load-on-startup>
</servlet>
//.........
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
//......................
</servlet-mapping>
</servlet-mapping>
//.........................................
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.
我的工程目录如下:
试过了一些网上给出的解决方案,但是还是解决不了所以想请高人帮助下~~