Announcement Announcement Module
No announcement yet.
Spring MVC: One controller handles multiple pages? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC: One controller handles multiple pages?

    Hi all,

    I am new to Spring and Java and could use some help. I am trying to implement the Spring MVC architecture in an existing project and trying to find the best solution for my scenario.

    Here is the scenario: I have two different web pages that perform very similar tasks. Both of these pages are mapped to the same bean in the servlet.xml file and therefore handled by the same controller. Depending on which link the user clicks on they will be redirected to one of these pages and the request will be handled by the controller. Depending on which page is chosen I need to pass different parameters from the controller to the service method that retrieves the data. Basically, the data is returned by calling the same webscript but it uses different parameter values. I want to stay away from passing the parameters in the querystring or hidden form fields. Also, I need to use a dynamic value for the formView property in the controller. Again, I am completely new to Java and Spring so I could be missing an easy solution.

    Below is some simplified code to illustrate my question. In this example if a user clicks on a rental properties link then I would be redirected to a rental properties page. If a user clicks on a for sale properties link then they will be redirected to a for sale page. Depending on the link clicked the same webscript will be called by the same controller but with different values.
    Servlet.xml file
    <bean name="property" class="PropertyController">
    		<property name="commandName"><value>property</value></property>
    		<property name="commandClass"><value>org.pojo.Properties</value></property>
    		<property name="formView"><value> What goes here? </value></property>
    		<property name="propertyService">
    			<ref bean="propertyServiceImpl"/>
    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="order"><value>0</value></property>
    		<property name="mappings">
    				<prop key="/propertiesForRent.htm">property</prop>
    				<prop key="/propertiesForSale.htm">property</prop>

  • #2
    Have a look at the reference documentation for Spring MVC (it is quite good at explaining all of this)


    • #3
      Thanks Mark, I read through that documentation yesterday but I wasn't able to find anything pertaining to my question. If there is a section of that documentation that you think will help me address my problem could you please point it out to me.



      • #4
        Any other ideas or suggestions are welcome...