Web-web configuration (1) __web

Source: Internet
Author: User

1, the Web configuration:
(1), set error Jump interface:

(2), String encoding configuration:

<!--character Set encoding configuration-->
  <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>
        <init-param>
            <param-name>forceEncoding</param-name>
            < param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping >
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

(3), configure Serlvet interception request out of Struct2

  <filter>
        <filter-name>redisp</filter-name>
        <filter-class> yamadv.com.filter.redispatcherfilter</filter-class>
        <init-param>
            <param-name> Includeservlets</param-name>
            <param-value>fileimageuploadservlet,uploadprocessorservlet</ param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name> redisp</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

The class of the configuration collection (Implementing filter):
Implementing multiple Servet Configurations in Web.xml

public class Redispatcherfilter implements Filter {public void Destroy () {} public void Dofilter (ServletRequest Req, Servletresponse resp, Filterchain chain) throws IOException, servletexception {httpservletrequ
        EST Request = (httpservletrequest) req;
        String target = Request.getrequesturi (); target = Target.lastindexof ("?") > 0? Target.substring (Target.lastindexof ("/") + 1, target.lastindexof ("?")-Target.lastindexo

        F ("/"): Target. Substring (Target.lastindexof ("/") + 1);
        SYSTEM.OUT.PRINTLN (target);

            if (This.includes.contains (target)) {RequestDispatcher RDSP = Request.getrequestdispatcher (target);
            System.out.println ("Go .... ..." + RDSP);..
        Rdsp.forward (req, resp);
        } else{Chain.dofilter (req, resp);

    } private arraylist<string> includes = new arraylist<string> (); Public VOID init (filterconfig config) throws servletexception {This.includes.addAll arrays.aslist (config.getinitparameter

    ("Includeservlets"). Split (",")); }

}

Servet to register (upload file to server):

<!--register Fileimageuploadservlet servlet-->
   <servlet>
        <servlet-name> Fileimageuploadservlet</servlet-name>
        <servlet-class>yamadv.com.upload.fileimageuploadservlet </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name> Fileimageuploadservlet</servlet-name>
        <url-pattern>/FileImageUploadServlet</url-pattern>
    </servlet-mapping>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.