Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the configuration file web.xml for Struts2?

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

What this article shares with you is about the configuration file web.xml of Struts2. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Any MVC framework needs to be integrated with Web applications, which has to rely on web.xml files. Only when configured in web.xml files can Servlet be loaded by applications.

In general, all MVC frameworks require Web applications to load a core controller. For Struts2 frameworks, you need to load FilterDispatcher. As long as the Web application is responsible for loading FilterDispatcher,FilterDispatcher, it will load the Struts2 framework.

Because Struts2 designs the core controller as a Filter rather than an ordinary Servlet. Therefore, in order for the Web application to load FilterDispatcher, you only need to configure FilterDispatcher in the web.xml file.

The standard configuration file is as follows:

Struts Blank struts2 org.apache.struts2.dispatcher.FilterDispatcher actionPackages org.apache.struts2.showcase.person configProviders lee.MyConfigurationProvider Struts2 / * index.html

All are configured as follows

Struts Showcase Application struts-prepare org.apache.struts2.dispatcher.filter.StrutsPrepareFilter struts-execute org.apache.struts2.dispatcher.filter.StrutsExecuteFilter sitemesh com.opensymphony.sitemesh.webapp.SiteMeshFilter struts-prepare / * sitemesh / * struts-execute / * Org.springframework.web.context.ContextLoaderListener org.apache.struts2.tiles.StrutsTilesListener org.apache.struts2.showcase.chat.ChatSessionListener org.apache.struts2.dispatcher.listener.StrutsListener dwr uk.ltd.getahead .dwr.DWRServlet debug true JspSupportServlet org.apache.struts2.views.JspSupportServlet 1 sitemesh-freemarker org.apache.struts2.sitemesh.FreemarkerDecoratorServlet default_encoding UTF-8 1 sitemesh-velocity Org.apache.struts2.sitemesh.VelocityDecoratorServlet default_encoding UTF-8 1 dwr/ dwr/* sitemesh-freemarker * .ftl sitemesh-velocity * .vm index.jsp default.jsp index.html No direct JSP access No-JSP * .jsp no-users Don't assign users to this role no-users

* as mentioned above, when configuring the FilterDispatcher class of Struts2, you can specify a series of initialization parameters. When configuring initialization parameters for the Filter, three initialization parameters are of special significance:

Config: comma-separated strings, each of which is the location of an XML configuration file. The Struts framework automatically loads the series configuration files specified by this property.

ActionPackages: comma-separated strings, each of which is a package space, and the Struts2 framework scans the Action under these package spaces.

ConfigProviders: configure your own ConfigurationProvider class.

You can also configure the Struts2 constant here, with one Struts2 constant per element, where the child element specifies the constant name and the child element specifies the constant value.

* the element is configured in the web.xml, and the URL intercepted by the Filter needs to be configured. Typically, we ask the Filter to intercept all user requests. You can go through element configuration.

The above is what the Struts2 configuration file web.xml is like, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report