Results 1 to 6 of 6

Thread: limit controllers to only accept POST

  1. #1
    Join Date
    Nov 2007
    Location
    Austin, TX USA
    Posts
    154

    Default limit controllers to only accept POST

    is this the appropriate way to make a controller only accept a POST?
    Code:
        <bean name="/hello.htm" class="org.web.InventoryController" >
        	<property name="supportedMethods" value="POST" />
        </bean>
    also is there a way to make it so that all controllers by default only accept POST so that i dont have to configure this property for each? i'm extending abstractcontroller. thanks.

  2. #2
    Join Date
    Jul 2008
    Location
    Almere
    Posts
    16

    Default

    Yes you can extend bean definitions and in such a manner inherrit the property.

    Code:
    <bean name="/hello.htm" class="org.web.InventoryController" >
    <property name="supportedMethods" value="POST" />
    </bean>
    
    <bean name="/hello2.htm" class="somecontroller" parent="/hello.htm" />
    the last bean will have the property supportedMethods set. Be sure that the property is actually supported by the "somecontroller" class.

  3. #3
    Join Date
    Nov 2007
    Location
    Austin, TX USA
    Posts
    154

    Default

    i thought all controllers support that property?

  4. #4
    Join Date
    Nov 2007
    Location
    Austin, TX USA
    Posts
    154

    Default

    nevermind i guess the standard controller class does not have that property. so would it make more sense to just create a new class that extends abstractcontroller and then extend that in all my controller classes instead of extending abstractcontroller, or to just use the method you provided?

  5. #5
    Join Date
    Nov 2007
    Location
    Austin, TX USA
    Posts
    154

    Default

    okay i was wrong, String[] getSupportedMethods() is in the WebContentGenerator superclass which SimpleFormController extends. so im just going to do this:
    Code:
      <bean id="baseController" class="org.springframework.web.servlet.mvc.SimpleFormController">
        	<property name="supportedMethods" value="POST" />
        </bean>
    and then extend that by using parent="baseController" on all my controllers

  6. #6
    Join Date
    Nov 2007
    Location
    Austin, TX USA
    Posts
    154

    Default

    or should i be doing this instead:
    Code:
        <bean id="baseController" abstract="true">
        	<property name="supportedMethods" value="POST" />
        </bean>
    and then extend by doing
    Code:
        <bean name="/upload.form" class="package.FileUploadController" parent="baseController">
        
            <property name="commandClass" value="examples.FileUploadBean"/>
            <property name="formView" value="fileuploadform"/>
            <property name="successView" value="confirmation"/>
    
        </bean>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •