[Spring] AbstractController

* AbstractController

– Abstract Class implemented Controller interface

– Return ModelAndView after process client’s request

– In controller inherited AbstractController, it only requires to implement handleRequestInternal method.

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- HandlerMapping -->
     <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
         <property name="mappings">
             <props>
                 <prop key="/listAbsCont.sp">listAbstractController</prop>
             </props>
         </property>
     </bean>

    <!-- ViewResolver -->
     <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="viewClass">
             <value>org.springframework.web.servlet.view.JstlView</value>
         </property>
         <property name="prefix">
             <value>jsp/</value>
         </property>
         <property name="suffix">
             <value>.jsp</value>
         </property>
     </bean>

    <bean id="listAbstractController" class="controller.ListAbstractController">
        <property name="supportedMethods" value="GET"></property>
    </bean>

</beans>

 

package controller;

import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.mvc.AbstractController;

public class ListAbstractController extends AbstractController {

    @Override
     protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        //parameter
         String param1 = request.getParameter("param1");

        //implement your require

        //ModelAndView
         ModelAndView modelAndView = new ModelAndView();
         modelAndView.setViewName("view_name");
         modelAndView.addObject("aaa", "bbb");

        return modelAndView;
     }
 }

Properties of AbstractController

Property Default Description
supportedMethod GET, POST HTTP method that conroller support
requirSession false Set whether require HTTPsession for processing request.
Exception occures when HttpSession doesn’t exist
cacheSeconds -1 cache header value for response in unit – second
0 – header doesn’t have  executing cache
-1 – doen’t have cache related header.
> 0 – include corresponding value in cache header
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s