SpringMVC and basic configuration of the interceptor

2010-11-28  来源:本站原创  分类:Java  人气:111 

Do not remember the lead pack.
web.xml:

<!-- Spring MVC  This core controller  DispatcherServlet Distributed to logical unit  -->
        <servlet>
                <servlet-name>coreAction</servlet-name>
                <servlet-class>
                        org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <!-- <init-param> Node is configured with the name "contextConfigLocation"
                Servlet Parameters, this parameter specifies the  Spring The location of the configuration file  "/WEB-INF/Config.xml".
                 If you omit this set, it defaults to the  "/WEB-INF/<servlet name>-servlet.xml", Its
                 In  <servlet name> To replace the Servlet name  ( In the current environment, the default value is
                /WEB-INF/Dispatcher-servlet.xml)
                <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/Config.xml</param-value>
                </init-param>
        -->
        <filter>
                <filter-name>encodingFilter</filter-name>
                <filter-class>
                        org.springframework.web.filter.CharacterEncodingFilter
                </filter-class>
                <init-param>
                        <param-name>encoding</param-name>
                        <param-value>UTF-8</param-value>
                </init-param>
                <param-name>forceEncoding</param-name>
                <param-value>true</param-value>

        </filter>

        <servlet-mapping>
                <servlet-name>coreAction</servlet-name>
                <url-pattern>*.kara</url-pattern>
                <url-pattern>*.do</url-pattern>
        </servlet-mapping>

Followed by spring configuration, as is no manual configuration in the web.xml configuration file to specify which spring, so the point is the configuration file name is: coreAction-servlet.xml.

<!--  View   -->
        <bean>
                <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>

        <!-- Mapping -->
        <bean>
                <property name="mappings">
                        <props>
                                <prop key="/login.do">loginAction</prop>
                                <prop key="toAddUser.kara">userAction</prop>
                                <prop key="addUser.kara">userAction</prop>
                        </props>
                </property>
                <!--  Registered interceptor   -->
                <property name="interceptors">
                        <list>
                            <ref bean="myInterceptor"></ref>
                        </list>
                </property>
        </bean>

        <!-- Controller -->
        <bean></bean>
        <bean></bean>
        <!--  Interceptor        -->
        <bean></bean>

Post a controller:

package com.biz;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

/**
 * @author Administrator
 *  Implement a single method  controller
 */
public class LoginAction implements Controller  {

        public ModelAndView handleRequest(HttpServletRequest request,
                        HttpServletResponse response) throws Exception {
                request.setAttribute("kara", "Hello!Kara!");

                return new ModelAndView("hello");
        }

}

Paste the interceptor:

package com.intercept;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class MyInterceptor  extends HandlerInterceptorAdapter{

        public void afterCompletion(HttpServletRequest arg0,
                        HttpServletResponse arg1, Object arg2, Exception arg3)
                        throws Exception {
                // TODO Auto-generated method stub
                System.out.println(" Callback implementation  ");
        }

        public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
                        Object arg2, ModelAndView arg3) throws Exception {
                // TODO Auto-generated method stub
                System.out.println(" After calling the controller  ");
        }

        public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
                        Object arg2) throws Exception {
                System.out.println(" Block start  :");
                System.out.println("***");
                System.out.println("&&&:"+arg2.getClass().getCanonicalName());
                System.out.println(arg2.getClass().getSimpleName());
                return false;
        }

}
相关文章
  • SpringMVC and basic configuration of the interceptor 2010-11-28

    Do not remember the lead pack. web.xml: <!-- Spring MVC This core controller DispatcherServlet Distributed to logical unit --> <servlet> <servlet-name>coreAction</servlet-name> <servlet-class> org.springframework.web.servlet.

  • SpringMVC basic configuration to study 2009-07-16

    The introduction of SpringMVC it is first necessary to configure the web.xml to configure the control request forwarding servlet - DispatcherServlet, <servlet> <servlet-name> Springmvc </ servlet-name> <servlet-class> org.springfra

  • Learn basic configuration switch ---- SpringMVC 2010-07-27

    Blog from the small strong The introduction of SpringMVC it, we must first configure the web.xml to configure control request forwarding servlet - DispatcherServlet, <servlet> <servlet-name> Springmvc </ servlet-name> <servlet-class&g

  • Struts1 basic configuration 2008-07-11

    The following records Struts1 basic configuration. 1, download Struts1.3 Links are as follows: http://struts.apache.org/download.cgi # struts1310 Second, copy all of the following packages lib to the project WEB-INF \ LIB next. 3, modify the web.xml

  • The following basic configuration OpenSolaris 2010-04-02

    To prepare for the formal development of tomorrow's graduation, haha ... afternoon intended to be used for some time to prepare tools and reference documents, the time when everything is ready to begin formal do ... Said the following about the opens

  • java log4j basic configuration Xiangjie 2010-04-14

    Two days to learn the basic configuration of Log4j a bit, really feel good is very strong. What is a small example of my configuration log4j properties configuration file log4j.properties The configuration of which says: log4j.rootLogger=info,A,B,C l

  • April 16 Ext.TreePanel basic configuration parameters 2010-04-16

    TreePanel basic configuration parameters: / / TreePanel configuration parameters 1.animate: true / / expand, shrink animation, false, then there is no animation 2.autoHeight: true / / auto height, defaults to false 3.enableDrag: true / / tree node ca

  • opensips installation and basic configuration 2010-05-06

    1. Official Website http://www.opensips.org/ the download package download opensips 2. Compile: tar zxvf opensips-1.6.2-tls_src.tar.gz cd opensips-1.6.2-tls 3. Before installing change the makefile: Remove Makefile in exclude_modules the db-mysql, my

  • Spring + XFire + WSS4J the basic configuration 2010-06-02

    http://www.blogjava.net/security/archive/2006/08/08/xfire_wss4j.html Java code 1. As many systems need to implement WS-Security standard, we SpringSide provided XFire + WSS4J the Demo, this paper SpringSide in Spring + XFire + WSS4J the basic configu

  • Codeigniter basic configuration 2010-06-17

    Leading technology for you to explain configuration codeigniter, codeigniter basic configuration information in the application / config / config.php file, the paper explained in detail each of the basic configuration options, to quickly grasp the co

  • Jetty basic configuration 2010-07-11

    Jetty is another area of Java - a good Web server, the server is also open source projects. Relative to the Tomcat, Jetty have more advantages ---- as - one embedded server, that is, if the application to add the Jar file Jetty, the application can a

  • CentOS 5.5 setup log - (5) LAMP basic configuration 2010-12-13

    LAMP installation is complete, we now do the basic configuration. (A) Apache (httpd) 1. To modify the type of the initial page # Nano / etc / httpd / conf / httpd.conf Find the DirectoryIndex, revised as the following: DirectoryIndex index.html index

  • STRUTS-2.2.1.1 version of the basic configuration 2010-12-25

    The new version came out, his basic configuration, and required one less frame pack: Requires only a few can be the following: commons-fileupload-1.2.1.jar commons-io-1.3.2.jar freemarker-2.3.16.jar javassist-3.7.ga.jar ognl-3.0.jar struts2-core-2.2.

  • CentOS 5.5 installation log - (5) LAMP basic configuration 2010-12-13

    LAMP installation is complete, we now do the basic configuration. (A) Apache (httpd) 1 to modify the initial page of type # Nano / etc / httpd / conf / httpd.conf Find DirectoryIndex, modify the following: DirectoryIndex index.html index.htm index.sh

  • CentOS 5.5 installation log - (7) LDAP installation and basic configuration 2010-12-15

    Now try installing LDAP (openLDAP). 1 Software Installation: yum -y install openldap openldap-clients openldap-servers nss_ldap samba samba-client openssl mod_ssl php-ldap php-pdo php-cli php-common perl-LDAP smbldap-tools perl-Digest-SHA1 perl-Diges

  • CentOS 5.2, Linux 2.6 + kernel, Apache + MySQL + PHP installation and basic configuration process will be recorded & & apache installed as system services 2011-03-16

    Quote CentOS 5.2, Linux 2.6 + kernel, Apache + MySQL + PHP installation and basic configuration record & & the apache installed as system services collections environment: This article in the Linux operating system is CentOS 5.2, Linux 2.6 + kerne

  • wine installation and basic configuration 2011-04-20

    Reference: http://forum.ubuntu.org.cn/viewtopic.php?f=121&t=107816 I was using the system: ubuntu 10.10 There are N number of ways online, I'll own a record of success to download it. First, install the sudo apt-get install wine Second, the configura

  • WIN2003 Internet Information Services (IIS) Manager of the basic configuration settings and applications and IIS optimization (Graphic DOC version) (rpm) 2011-04-21

    WIN2003 Internet Information Services (IIS) Manager of the basic configuration settings and applications and IIS optimization (Graphic DOC version) (rpm)

  • Oracle database installation is uninstalled and basic configuration 2010-08-19

    1, install the Oracle database products 1) Install Oracle database products Note: a) ISO files need to be installed into the virtual drive files, or extract the installation, must not simply double-click to open with winrar software installation. b)

  • MySQL in Windows, the basic configuration 2010-09-26

    Description: This article is for mysql-noinstall version, which is extracted version of the basic configuration in Windows Operating system: Windows XP MySQL version: mysql-5.1.50-win32 1, download MySQL-extracting archive mysql-noinstall-5.1.50-win3