IntelliJ IDEA中Tomcat 8.5启动JSP报404资源不可用,配置排查无效求助
Troubleshooting Tomcat 8.5 + IntelliJ IDEA JSP 404 Error
Hey there, let’s work through this 404 issue you’re hitting when launching JSPs in IntelliJ IDEA with Tomcat 8.5. Even after checking configuration classes, there are a few common gotchas in artifact setup and web.xml that often slip through the cracks. Let’s break them down:
1. Audit Your Tomcat Artifact Configuration
First, let’s make sure your artifact is deployed correctly in IDEA:
- Check Deployment Descriptors: Open
File > Project Structure > Artifactsand verify that yourweb.xmlis listed under "Deployment Descriptors"—it shouldn’t be grayed out, and the file path should point to the correctWEB-INF/web.xmlin your project. - Validate Output Directory: Ensure the artifact’s output path matches what Tomcat expects. IDEA often uses
out/artifacts/[your_project_name]by default; confirm this directory contains your compiled classes, JSP files, andWEB-INFfolder. If not, reconfigure the artifact to include all necessary resources. - Confirm Context Root: The Context Root setting in the artifact configuration dictates the base URL for your app. For example, if it’s set to
/my-web-app, you’ll need to access your JSP athttp://localhost:8080/my-web-app/your-page.jsp—not just the root/your-page.jsp. A mismatch here is one of the most common 404 causes.
2. Dig Into web.xml Settings
Next, let’s rule out issues in your deployment descriptor:
- Welcome File List: If you’re hitting 404 when accessing the default homepage, check that your
web.xmlincludes the correct JSP in<welcome-file-list>:
Double-check that<welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>index.jspactually exists in your webapp root directory (not insideWEB-INF). - Servlet Mapping Validation: If your JSP is accessed via a servlet, confirm the
url-patternmatches the path you’re using. For example:
Also, ensure the servlet’s forward path is correct (e.g.,<servlet> <servlet-name>HomeServlet</servlet-name> <servlet-class>com.example.HomeServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HomeServlet</servlet-name> <url-pattern>/home</url-pattern> </servlet-mapping>request.getRequestDispatcher("/WEB-INF/views/home.jsp").forward(request, response)—paths here are relative to the webapp root). - web.xml Placement: Make sure
web.xmlis located directly in theWEB-INFfolder of your webapp directory (usuallysrc/main/webapp/WEB-INFin Maven/Gradle projects). IDEA won’t recognize it if it’s in the wrong place.
3. Quick Additional Checks
- JSP File Location: JSPs inside
WEB-INFcan’t be accessed directly via URL—they need to be forwarded by a servlet. If you’re trying to hit a JSP directly, move it to the webapp root or a subfolder outsideWEB-INF. - Clean & Rebuild: Sometimes IDEA’s cached files cause deployment issues. Run
Build > Clean Project, thenBuild > Rebuild Project, and restart Tomcat. - Check Tomcat Logs: Head to your Tomcat installation’s
logsfolder and look atlocalhost.logorcatalina.out—these logs often include specific details about which resource Tomcat is failing to find, which can pinpoint the issue fast.
Give these steps a shot—most of the time, this 404 error boils down to a small misconfiguration in artifact setup or web.xml. Let me know if any of these fix your problem!
内容的提问来源于stack exchange,提问作者Maryia Yurchak
相关产品推荐
相关产品推荐

