Struts2的配置,和简单的事例!!!!!!!!!!!

配置struts2的时候一直出现如图问题。配置都没有问题。????????????????????图片说明

/CatchServletApi,看看你的web.xml配置

S

第一步:导入Spring扎包
第二步:在Web.xml文件添加启动Spring监听器
<!-- 监听器-->

org.springframework.web.context.ContextLoaderListener

第三步:在Web-INF下建立Spring的配置文件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"

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-3.0.xsd  
http://www.springframework.org/schema/context  
http://www.springframework.org/schema/context/spring-context-3.0.xsd  
http://www.springframework.org/schema/tx  
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
http://www.springframework.org/schema/aop   
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  
</beans>

第四步:在src下建立一个测试类 在Spring配置文件中添加Bean标签 有id属性 class属性 init-method属性请求名

第五步:建立一个源文件夹config把Sping配置文件移入到(cunfif)在wep.xml文件里写入
(给Spring配置文件改名换地方)
<!-- 给Spring配置文件改名换地方-->

contextConfigLocation
classpath:applicationContext.xml

** S

第一步:导入Struts2扎包

第二步:在Web.xml文件添加fieter过滤器

过滤器:

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

第三步:在cunfjg下建立struts.xml(配置文件)

第四步:在struts配置文件中测试text类(添加一个Action标签 name属性 class属性 method属性请求名)

**

SS

第一步:先导入Struts和Spring联合扎包,

第二步:在把Struts的配置文件class属性的路径改为 Spring id属性的值

第三步:在Spring配置文件中添加request作用域scope属性=“requet”然后再web.xml里面添加request
应用requet作用域监听器:

org.springframework.web.context.request.RequestContextListener

H

第一步:导入hibernate扎包orm插件包管理

第二步:spring以组件的方式管理hibernate在Spring配置文件中添加
数据源:


oracle.jdbc.driver.OracleDriver


jdbc:oracle:thin:@localhost:1521:turing


hibernate
sa




<!-- hibernate属性设置 -->


org.hibernate.dialect.OracleDialect
update
true


<!-- 实体类声明 -->


classpath:com/turing/manage/entity



第四部:测试框架
在src下建立,IDAO 模型,控制器,实体类,实现类,接口,
在Spring配置文件里注入IDao :


在控制器里调用模型,service,无中生有一个查询的方法,接口创建这个方法,实现类实现这个方法,

public void query(){
    Object list = testService.query("from Post");
    System.out.println("---"+list);
}

在Spring配置文件中注入service,调用已注入的Dao

<bean id="testAction1" class="com.turing.manage.action.TestAction1" >
    <property name="testService" >
        <bean class="com.turing.manage.serviceimpl.TestServiceImpl" >
            <property name="dao" ref="dao"></property>
        </bean>
    </property>
</bean>

第五步:在Spring配置文件添加事务,而且需要添加AOP事务需要的炸包

事务 :

<!-- TransactionManager 事务管理 -->

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>
<!-- 
第一个 * —— 通配 任意返回值类型 
第二个 * —— 通配 包com.turing.system.service下的任意class
第三个 * —— 通配 包com.turing.system.service下的任意class的任意方法
 .. —— 通配 方法可以有0个或多个参数
 -->
<aop:config>
    <!-- 管理事务操作 -->
    <aop:pointcut id="servicesPointcut2" expression="execution(* com.turing.manage.service.impl.*.*(..))" />        
    <aop:advisor advice-ref="txAdvice" pointcut-ref="servicesPointcut2" />
</aop:config>
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 事务控制 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="query*" propagation="REQUIRED" />
        <tx:method name="list*" propagation="REQUIRED" />
        <tx:method name="select*" propagation="REQUIRED" />
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="update*" propagation="REQUIRED" />
        <tx:method name="del*" propagation="REQUIRED" />
        <tx:method name="remove*" propagation="REQUIRED" />
        <tx:method name="report*" propagation="REQUIRED" />
        <tx:method name="show*" propagation="REQUIRED" />
        <tx:method name="detail*" propagation="REQUIRED" />
        <tx:method name="edit*" propagation="REQUIRED" />
        <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>

第六步:在wep.xml配置文件添加Spring提供的过滤器打开和关闭session必须
在Struts2过滤器前面
<!-- Spring提供的过滤器-打开和关闭session -->

openSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

    <init-param>
        <param-name>singleSession</param-name>
        <param-value>true</param-value>
    </init-param>
 </filter>    
 <filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
 </filter-mapping>  

第七部:把spring原数据源替换成连接池数据源
连接池数据源

        <!--数据源配置 -->
<bean id="dataSource"   class="com.mchange.v2.c3p0.ComboPooledDataSource"     destroy-method="close"> 
    <!--驱动类-->
     <property name="driverClass">
        <value>oracle.jdbc.driver.OracleDriver</value>
     </property>
    <!--连接字符串-->
     <property name="jdbcUrl">
        <value>jdbc:oracle:thin:@localhost:1521:unitocom</value>
     </property>
     <property name="user">
        <value>hibernate</value>
    </property>
    <property name="password">
        <value>sa</value>
    </property>
    <property name="minPoolSize">     
        <value>5</value>     
    </property>      

<!--连接池中保留的最大连接数。Default: 15 -->



30

    <property name="initialPoolSize">      
        <value>10</value>      
    </property>      
    <property name="maxIdleTime">      
        <value>60</value>      
    </property>     
    <property name="acquireIncrement">     
        <value>5</value>     
    </property>      

<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements

属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。

如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->



0



<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->



60



<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->



30



<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效

保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试

获取连接失败后该数据源将申明已断开并永久关闭。Default: false-->



true



<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的

时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable

等方法来提升连接测试的性能。Default: false -->



false


一、检查你有没有stutrs.xml文件
二、检查你的struts.xml文件配置的是否正确
问题应该就在这两个答案附近,八九不离十,因为你提供的有限,我只能判断到这!

错误日志挺明确的啊,说你某个文件里配置的路径有问题,包含了<:>,至于是哪个文件里配的错误了,看下你错误日志里java.nio.file.path.InvalidPathException那一行最后面

你缺少的配置影响了你的系统初始化,以至于不能加载,所以你也要检查下你的struts.xml中的两个标配有没有

检查你有没有stutrs.xml文件
检查你的struts.xml文件配置的是否正确
问题应该就在这两个答案附近,八九不离十,因为你提供的有限,我只能判断到这!

看一下你有没有struts.xml配置文件,另外web.xml里面是否配置了过滤器。

web.xml配置文件看一下有没有配置对

老弟这个技术已经过时了。学了毫无用处。