Announcement Announcement Module
Collapse
No announcement yet.
limit controllers to only accept POST Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      i thought all controllers support that property?

      Comment


      • #4
        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?

        Comment


        • #5
          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

          Comment


          • #6
            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>

            Comment

            Working...
            X