This article mainly introduces the url interception of Struts1_related information compiled by the Power Node Java Academy. Friends in need can refer to
Struts1 url interception
First let's analyze ActionServlet in depth. We use breakpoint debugging to look at the underlying source code. Because this instance is submitted in post mode, set the breakpoint to the doPost method.
We debug the program and enter the method inside doPost:
This method is very Importantly, it is the core method of ActionServlet running.
We enter this method:
Then continue to enter:
We suddenly discovered that such a method is the processPath method, which is a method of intercepting strings. The source code of this method is as follows:
/** * <p>Identify and return the path component(from the request URI) that * we will use to select an <code>ActionMapping</code> with which todispatch. * If no such path can be identified,create an error response and return * <code>null</code>.</p> * * @param request The servlet request weare processing * @param response The servlet response weare creating * * @exception IOException if an input/outputerror occurs */ protectedString processPath(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = null; // For prefix matching, match on the path info (if any) path = (String) request.getAttribute(INCLUDE_PATH_INFO); if (path == null) { path = request.getPathInfo(); } if ((path != null) && (path.length() > 0)) { return (path); } // For extension matching, strip the module prefix and extension path = (String) request.getAttribute(INCLUDE_SERVLET_PATH); if (path == null) { path = request.getServletPath(); } String prefix = moduleConfig.getPrefix(); if (!path.startsWith(prefix)) { String msg =getInternal().getMessage("processPath"); log.error(msg + " " + request.getRequestURI()); response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); return null; } path = path.substring(prefix.length()); int slash = path.lastIndexOf("/"); int period = path.lastIndexOf("."); if ((period >= 0) && (period >slash)) { path = path.substring(0, period); } return (path); }
Analyze this code:
path = (String)request.getAttribute(INCLUDE_PATH_INFO); if (path == null) { path = request.getPathInfo(); } if ((path != null) && (path.length() > 0)) { return (path); }
This code first determines whether the path information exists in javax.servlet.include.path_info. Here you need to know the Dangdang one This attribute value only exists if the page is displayed in RequestDispatcher.include mode. So if there is no value here, it will enter the path=request.getPathInfo() program. The value obtained by getPathInfo here is the path information relative to the servlet.
// For extension matching, stripthe module prefix and extension path = (String) request.getAttribute(INCLUDE_SERVLET_PATH); if (path == null) { path = request.getServletPath(); } String prefix = moduleConfig.getPrefix(); if (!path.startsWith(prefix)) { String msg =getInternal().getMessage("processPath"); log.error(msg + " " + request.getRequestURI()); response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); return null; }
This code is to determine whether javax.servlet.include.servlet_path has a value. This attribute value only exists when a page is displayed in requestDispatcher.include mode, so the value here does not exist. Then enter path = request.getServletPath(); This method is to get the substring after returning the request URI context, so the return value here is "/" and the access page name and suffix (is this the same as what my mvc instance intercepts? principle). Then enter the following code:
path = path.substring(prefix.length()); intslash = path.lastIndexOf("/"); intperiod = path.lastIndexOf("."); if((period >= 0) && (period > slash)) { path = path.substring(0, period); } return (path);
The method here is mainly the same as mine above, the main thing is to remove the suffix.
The above is the detailed content of Detailed introduction to Struts1 url interception. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools