Solution to the problem that struts and servlet cannot coexist
In a project, if we use both struts 2 and servlet, we may not be able to access the servlet normally when the project is running because all requests are intercepted when configuring the struts filter.
The following is the servlet configuration
When we make a request on the page, struts 2 will intercept all requests and will not respond normally to servlet requests
The error message is: HTTP status 404 - there is no action mapped for namespace / and action name myservlet
This is because struts 2 regards servlet as action, because both servlet and action have no suffix
resolvent:
Three methods are described below
Method 1:
Add after servlet Servlet end, including web Where servlets are used in XML configuration files and pages (of course, anything, such as hello)
Page access http://localhost:8080/project/MyServlet.servlet
Method 2:
In struts Add the request suffix constant processed by struts 2 under the node in XML:
This attribute specifies the request suffix to be processed by struts 2. The default value of this attribute is action, that is, all matching * Action requests are processed by struts 2. If the user needs to specify multiple request suffixes, the suffixes are separated by English commas (,).
Method 3:
On the web Modify the configuration of struts 2 intercepting page requests in XML:
customary
Change to
The request path of the servlet does not change
summary
The above is all about the solution to the problem that struts and servlet cannot coexist. I hope it will be helpful to you. Welcome to: struts 2 modify upload file size limit method analysis, struts 2 development process and detailed configuration, etc. If you have any questions, you can leave a message at any time. Xiaobian will reply to you in time.