环境:eclipse 3.6 +
创建项目
一、修改JSP文件 文字样式
Preferendce ->输入 jsp ->选中 jsp Files -> 将encoding 设置为 chinese ,National Standard ,每次创建的jsp文件,默认GB18030GB18030 GB18030
二、创建数据库 mysql -uroot -p
三、报错
The server does not support version 3.0 of the J2EE Web module specification
把
<installed facet="jst.web" version="3.0"/>
改为
<installed facet="jst.web" version="2.5"/>
即可
四、报错 java.runningtime classNotFound Class.forName("com.mysql.jdbc.Driver");上面的异常的抛出主要有几个方面:1、最容易想到的,就是你的from是实体类而不是表名,这个应该大家都知道,注意大小写
2、你的hibernate配置文件中没有加入相应的映射文件<mapping resource=" " />
3、如果上面两方面都对了,还有错,基本上处于崩溃状态,哈哈....一般是上面两种原因,还是不行,那就是你hql语句有错了,好好检查一下,仔细点,不行就重新写一遍,因为我就是因为一个中文空格被折腾了两天啊,就是找不出哪儿出错了,怎么看怎么对,可是就是报错,哈哈...很崩溃的。
4、检查引入的包是否有错 以下正确引入包import javax.persistence.GeneratedValue;
import javax.persistence.Id;
七、MVC 模式 (切换到编辑看)
整合步骤:
1. 修改web.xml加入 struts的filter
2. 再加入spring的listener,这样的话,webapp一旦启动,spring容器就初始化了
3. 规划struts的action和jsp展现
4. 加入struts.xml
a) 修改配置,由structs-spring-plugin插件或 spring 容 器 替代struts产生Action对象
5. 修改action配置
a) 把类名改为bean对象的名称,这个时候就可以使用首字母小写了
struts的读常量查找文件顺序:
1. struts-default.xml
2. struts-plugin.xml
3. struts.xml
4. struts.properties
5. web.xml
第40讲 和 第49讲 分别介绍两种生成、管理 action bean 方法
结合点:Struts2 通过自身的 spring -plugin 插件生成action bean ,默认@scope属性为prototype 。生成的action bean 与spring 生成的bean 分开 用两个容器管理,action bean 头上不用写anotation 标记,struct2-spring-plugin 插件默认情况下,会根据struct2.xml 配置文件的class路径,生成 一个 action bean ,名字 与struct2.xml 配置的action名字一致,如果再加上anotation 标记,例如: @compont("user "),则 spring 会为其又生产一个action bean ,一共有两个action bean ,一个由structs2 -spring -plugin 插件管理,另一个由spring 管理,但当action bean 需要用到的bean (非action Bean , 例如:Dao层 的 userDao bean 、service 层的userManager bean ),则由Spring 装载到action bean中.。
第二种方法 (action头上加anotation 标记)由spring容器管理
在action 头上加 @compont("user") 和 @Scope(“prototype”)标记,prototype 表示每次请求都生成一新的action bean ,这个标记必须记得写,要想将Bean交给spring 管理,在structs2 配置文件中 ,将action 的class路去掉,改为 bean 的名字,这样spring 就会为structs2 装载action bean ;
<filter-name>openSessionInView</filter-name>
<filterclass>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sf</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<aop:config>
<aop:pointcut id="bussinessService"
expression="execution(public * com.bjsxt.registration.service.*.*(..))" />
<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="exists" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>