问题描述
web.xml: <?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener> <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:beans.xml</param-value></context-param><!--<filter> <filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter> <filter-mapping> <filter-name>struts2</filter-name><url-pattern>/*</url-pattern> </filter-mapping>--><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app> struts2.xml <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="useraction" namespace="/user" extends="struts-default"><action name="userAction" class="userAction"><result name="success">/index.jsp</result></action></package><!-- Add packages here --> </struts> beans.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"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <context:annotation-config /><context:component-scan base-package="com.kettas"></context:component-scan> <!-- datasource --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><!-- results in a setDriverClassName(String) call --><property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /><property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" /><property name="username" value="spc" /><property name="password" value="spc" /></bean><!-- sessionfactory --><bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="annotatedClasses"><list><value>com.kettas.entity.Product</value><value>com.kettas.entity.User</value><value>com.kettas.entity.Order</value><value>com.kettas.entity.Item</value></list></property> <property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="current_session_context_class">thread</prop></props></property></bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory" /></bean><bean id="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><aop:config><aop:pointcut id="bussinessService"expression="execution(public * com.biz..*.*(..))" /><aop:advisor pointcut-ref="bussinessService"advice-ref="txAdvice" /></aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="login" read-only="true" /><tx:method name="select*" read-only="true" /><tx:method name="insert" propagation="REQUIRED"/><tx:method name="update" propagation="REQUIRED"/><tx:method name="delete" propagation="REQUIRED"/></tx:attributes></tx:advice></beans> action: @Controller("userAction")@Scope("prototype")public class UserAction extends ActionSupport {private User user; private UserBiz userBiz;private Map<String, Object> session; public Map<String, Object> getSession() {return session;} public void setSession(Map<String, Object> session) {this.session = session;} public User getUser() {return user;} public void setUser(User user) {this.user = user;} public UserBiz getUserBiz() { return userBiz; } @Resource(name = "userBiz") public void setUserBiz(UserBiz userBiz) { this.userBiz = userBiz; } public String login() { User userLogin = userBiz.login(user.getName(), user.getPassword()); if (userLogin != null) { session.put("login", userLogin);System.out.println("aaaaaaa"); return "success"; } else { addActionError("用户名密码错误"); return "error"; }}}
解决方案
项目名 tomcat不支持
解决方案二:
struts.xml没有配置<constant name="struts.objectFactory" value="spring" />
解决方案三:
class="userAction" 是在什么地方映射的?