有SSH方面的高手吗?我原来有个工程1是SSH做的,后来新建一工程,先做了个登陆,还用SSH,我按照工程1的配置写,开始配struts,没连数据库,只是判断特值可以登陆成功,然后配Spring+hibenate,开始web.xml中没配<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
< stener-class>
< stener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>,index.jsp可以打开,提交后报No wedapplicatontext,就是说找不到资源文件,配上这后,就报404了,这是什么问题呢
附上我的三个xml文件
web.xml
<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>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>struts-config.xml
<struts-config>
<data-sources />
<form-beans>
<!--登陆Form -->
<form-bean name="loginForm" type="webexp.form.LoginForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<!--登陆 -->
<action path="/login" name="loginForm" scope="request" type="webexp.action.LoginAction">
<forward name="success" path="/main.jsp"/>
<forward name="fail" path="/login.jsp"/>
</action>
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
applicationContext.xml
<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.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<property name="mappingResources">
<list>
<value>webexp/mapping/Operator.hbm.xml</value>
</list>
</property>
</bean>
<bean id="operdao" class="webexp.dao.OperatorDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="operser"
class="webexp.service.OperatorService">
<property name="operDao" ref="operdao"></property>
</bean>
<bean name="/login" class="webexp.action.LoginAction">
<property name="operSer" ref="operser"></property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
<listener-class>
org.springframework.web.context.ContextLoaderListener
< stener-class>
< stener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>,index.jsp可以打开,提交后报No wedapplicatontext,就是说找不到资源文件,配上这后,就报404了,这是什么问题呢
附上我的三个xml文件
web.xml
<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>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>struts-config.xml
<struts-config>
<data-sources />
<form-beans>
<!--登陆Form -->
<form-bean name="loginForm" type="webexp.form.LoginForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<!--登陆 -->
<action path="/login" name="loginForm" scope="request" type="webexp.action.LoginAction">
<forward name="success" path="/main.jsp"/>
<forward name="fail" path="/login.jsp"/>
</action>
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
applicationContext.xml
<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.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<property name="mappingResources">
<list>
<value>webexp/mapping/Operator.hbm.xml</value>
</list>
</property>
</bean>
<bean id="operdao" class="webexp.dao.OperatorDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="operser"
class="webexp.service.OperatorService">
<property name="operDao" ref="operdao"></property>
</bean>
<bean name="/login" class="webexp.action.LoginAction">
<property name="operSer" ref="operser"></property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
是不是这个文件没有啊
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>classpath:applicationContext.xml </param-value>
</context-param>换成这样试下:
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>classpath:applicationContext.xml </param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
applicationContext.xml 这个文件应该是自动主加载的
No WebApplicationContext found: no ContextLoaderListener registered
所以才加的Litener,可加了以后,http://localhost:8080/webexp,就报:HTTP Status 404 - /webexp/
楼主最好详细看看到底是哪个环节报的404!
<action path="/login" name="loginForm" scope="request" type="webexp.action.LoginAction">
改
<action path="/login" name="loginForm" scope="request" type="org.springframework.web.struts.DelegatingActionProxy"> 在。web.xml中只要加这几句代码就可以了
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>在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> <!-- WEBUI -->
<bean name="/user" class="com.web.action.OrderAction">
<property name="userService" ref="userService" />
</bean> <!-- BIZ -->
<bean id="userService" parent="serviceTemplate">
<property name="target" ref="userServiceTarget" />
</bean> <bean id="serviceTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager" />
<property name="transactionAttributes">
<props>
<prop key="a*">PROPAGATION_REQUIRED</prop>
<prop key="d*">PROPAGATION_REQUIRED</prop>
<prop key="u*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <bean id="userServiceTarget" class="com.biz.userService">
<property name="userDao" ref="userDao" />
</bean>
<!-- DAO -->
<bean id="userDao" class="com.dao.userOrderDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
</beans>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">
jdbc:sqlserver://127.0.0.1:1433;databaseName=UserInfor
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">
sql2k5_eSale
</property>
<property name="connection.password">accp</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/entity/SaleProduct.hbm.xml" />
<mapping resource="com/entity/SaleOrder.hbm.xml" />
<mapping resource="com/entity/CusCustomer.hbm.xml" />
<mapping resource="com/entity/SaleOrderLine.hbm.xml" /> </session-factory></hibernate-configuration>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>在web.xml文件中只加上这个试试
http://download.csdn.net/source/649512
<param-name>contextConfigLocation </param-name>
<param-value>/WEB-INF/applicationContext.xml </param-value>
</context-param> 在web.xml文件中只加上这个,和没加一样,可以进index.jsp不过提交后报
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
这是说找不到资源文件吧,然后你在此web.xml中一加上那两句,就报404,你贴出编译的时错:
log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester).
log4j:WARN Please initialize the log4j system properly.
2008-11-8 16:28:05 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2008-11-8 16:28:05 org.apache.catalina.core.StandardContext start
严重: Context [/jhwl] startup failed due to previous errors
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在网上查过资料之后,最后把这个listener写成如下形式就ok了
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
这样可以开首页了,可是提交后报这错,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
这句加个*就行了