开发Spring MVC应用程序(3-3)

类别:Java 点击:0 评论:0 推荐:

l         现在需要修改springapp-servlet.xml,定义新的表单和对应控制器

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">

 

<!--

  - Application context definition for "springapp" DispatcherServlet.

  -->

 

<beans>

 

    <!--  Controller for the initial "Hello" page -->

    <bean id="springappController" class="web.SpringappController">

        <property name="productManager">

            <ref bean="prodMan"/>

        </property>

    </bean>

 

    <!--  Validator and Form Controller for the "Price Increase" page -->

    <bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/>

    <bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">

        <property name="sessionForm"><value>true</value></property>

        <property name="commandName"><value>priceIncrease</value></property>

        <property name="commandClass"><value>bus.PriceIncrease</value></property>

        <property name="validator"><ref bean="priceIncreaseValidator"/></property>

        <property name="formView"><value>priceincrease</value></property>

        <property name="successView"><value>hello.htm</value></property>

        <property name="productManager">

            <ref bean="prodMan"/>

        </property>

    </bean>

 

    <bean id="prodMan" class="bus.ProductManager">

        <property name="products">

            <list>

                <ref bean="product1"/>

                <ref bean="product2"/>

                <ref bean="product3"/>

            </list>

        </property>

    </bean>

 

    <bean id="product1" class="bus.Product">

        <property name="description"><value>Lamp</value></property>

        <property name="price"><value>5.75</value></property>

    </bean>

 

    <bean id="product2" class="bus.Product">

        <property name="description"><value>Table</value></property>

        <property name="price"><value>75.25</value></property>

    </bean>

 

    <bean id="product3" class="bus.Product">

        <property name="description"><value>Chair</value></property>

        <property name="price"><value>22.79</value></property>

    </bean>

 

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">

        <property name="basename"><value>messages</value></property>

    </bean>

 

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

        <property name="mappings">

            <props>

                <prop key="/hello.htm">springappController</prop>

                <prop key="/priceincrease.htm">priceIncreaseForm</prop>

            </props>

        </property>

    </bean>

 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="viewClass">

           <value>org.springframework.web.servlet.view.JstlView</value>

        </property>

        <property name="prefix"><value>/WEB-INF/jsp/</value></property>

        <property name="suffix"><value>.jsp</value></property>

    </bean>

</beans>

本文地址:http://com.8s8s.com/it/it16191.htm