前辈们.. 如果你也有过这样的痛苦.. 请你进来帮帮我..
这是一个在ssh 整合问题..
HTTP Status 404 - Servlet action is not available
开始的时候 .. 我以为是我的配置文件有问题.. 然后不断的找..
结果发现.. 就算是 复制 粘贴.. 他也抱怨这个错..
无数次的重启 tomcat 修改配置文件.. 每一次希望都被 submit 后的 这个字符串磨灭...
然而发现.. 是在 applicationContext.xml的配置文件中.. 一但配置了 <bean id="sessionFactory"/> 的bean 他就出这个问题..
删除这个bean 他便可以正确提交.. 但.. 我要如何配置这个bean呢.. 我真地好痛苦.. 几天了 .. 都没解决..
这种痛苦... 你是不是也有过.. 如果有.. 请你帮帮我.. 但对不起.. 我没分了..
我用的开发工具是 Tomcat 5.5 + MyEclipse6.0 + struts1.2 + hibernate3.1 + spring1.2
以下是相关代码..
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:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>encoding</filter-name>
<filter-class>
org.xml.myzngt.filter.EncodingFilter
</filter-class>
<init-param>
<param-name>charSet</param-name>
<param-value>gbk</param-value>
</init-param>
</filter>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<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>
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 name="/user"
class="org.xml.myzngt.struts.action.UserAction">
</bean>
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
destroy-method="close">
<property name="jndiName">
<value>java:comp/env/jdbc/mldn</value>
</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.connection.autocommit">true</prop>
<!-- 显示sql语句 -->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
</list>
</property>
</bean>
</beans>
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="userForm"
type="org.xml.myzngt.struts.form.UserForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action attribute="userForm" input="/jsp/errors.jsp"
name="userForm" parameter="status" path="/user" scope="request"
validate="true">
<forward name="success" path="/jsp/index.jsp"></forward>
<forward name="failure" path="/jsp/register.jsp"></forward>
</action>
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
<message-resources
parameter="org.xml.myzngt.struts.ApplicationResources" />
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
</struts-config>
数据源配置 zhinangtuan.xml
<Context path="/zhinangtuan" docBase="E:\myeclipsworkspace\MyZhiNangTuanDemo\WebRoot" reloadable="true" debug="0" >
<Resource
name="jdbc/mldn"
type="javax.sql.DataSource"
username="root"
password="piaoxiang"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
url="jdbc:mysql://localhost:3306/test?autoReconnect=true"
maxActive="4"/>
</Context>
问题页面...
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %>
<%@ page contentType="text/html;charset=gbk"%>
<html:html lang="true">
<head>
<title>register</title>
</head>
<body>
<center>
</center>
<h1 align="center">用户注册</h1>
<html:form action="/user.do" method="post">
<center>
用户ID:<html:text property="userid"></html:text><br/>
用户密码:<html:text property="userpwd"></html:text><br/>
确认密码:<html:text property="confirmpws"></html:text><br/>
丢失密码问题:<html:text property="userques"></html:text><br/>
丢失密码回答:<html:text property="userans"></html:text><br/>
验证码:<html:text property="checkcoked"></html:text><img alt="验证码" src="image.jsp"><br/>
<input type="hidden" value="register" name="status"/>
<input type="hidden" value="1" name="type" />
<html:submit></html:submit><html:reset></html:reset><br/>
</center>
</html:form>
</body>
</html:html>
代码很长...
这是程序员成长路上的痛苦.. 请前辈们 帮帮我吧..
拜托了..
[解决办法]
有时候程序会出莫名其妙的错误...
有时候发现写程序就是在玩大家来找碴...呵呵~~~
[解决办法]
试一下这样行不行?
<!-- session -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:/hibernate.cfg.xml</value>
<!-- file:src/hibernate.cfg.xml -->
</property>
</bean>