06-SSH综合案例:前台首页访问

时间:2023-03-09 02:00:31
06-SSH综合案例:前台首页访问

1.5 编码实现:

1.5.1 首页显示:

复制所有文件到工程下:

*  css

*  js

*  image

复制页面到工程WEB-INF/jsp/

* 将后缀.htm改为jsp

访问一个Action通过Action转向到JSP.

* 创建包:

* 编写Action:

* 直接返回一个字符串.

* 配置struts.xml

<!-- 配置首页访问的Action -->
                       <!-- 不应该这么写,应该把IndexAction交给Spring来管理 -->
                       <!--
                      <action name="index" class="cn.itcast.shop.index.IndexAction">
                        -->
                      <action name="index" class="indexAction">
                      <result name="indexSuccess">/WEB-INF/jsp/index.jsp</result>
                      </action>

* 配置applicationContext.xml

<!-- 上面是Spring的基本配置,下面就要开始配置Action============================ -->
                         <!-- 这个时候这个类就由Spring来创建了 多例的 线程安全的问题 交由Spring来管理了-->

                         <bean id="IndexAction" class="cn.itcast.shop.index.IndexAction" scope="prototype"/>
                         </beans>

06-SSH综合案例:前台首页访问

06-SSH综合案例:前台首页访问

struts.xml中Action的class要和applicationContext.xml的id一致。