简体   繁体   中英

Configuring struts 2 to load on startup

My Struts 2 application currently loads resource when a request comes in for the resource(jsp,action). I what all resources needed, to be loaded once the application is first deployed unto the container to have fast response times. How can I accomplish this? [Note] I am using Tomcat as my Servlet Container.

Why don't you try to implement Filters... as Filter starts with the application once it loaded and it will probably be helpful in order to load the resources.

You can add up your code in init method as it will be initiated with the start of container.

public class TestFilter implements Filter
{


    public void init( FilterConfig config ) throws ServletException
    {
        System.out.println( "PUBLIC  Fileter Started." );
    }
    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain )
            throws IOException, ServletException
    {
//DO NOTHING
    }


}

And do add an entry in web.xml

<filter>
        <filter-name>TestFilter</filter-name>
        <filter-class>com.filter.TestFilter</filter-class>


    </filter>

    <filter-mapping>
        <filter-name>TestFilter</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM