为何无法访问Tomcat中/webapps/Root下的xx.jsp文件?
Hey there! Let's break down why your xx.jsp is throwing a 404 error while xx.html loads just fine—here are the most common causes and fixes to check:
Incorrect file placement
Make sure yourxx.jspis in the right directory. If you're accessing it viahttp://localhost:8080/xx.jsp, it needs to live directly in theROOTfolder (same location as the workingindex.jsp). If you put it in a subfolder, you'll need to include that path in your URL, likehttp://localhost:8080/your-subfolder/xx.jsp.Missing JSP servlet mapping
Tomcat relies on a built-in servlet to process.jspfiles. Check your Tomcatconf/web.xmlfile for this default mapping—if it's missing or modified, Tomcat won't know how to handle JSP requests. Look for this section:<servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> <url-pattern>*.jspx</url-pattern> </servlet-mapping>If it's not there, add it back (you might need to restart Tomcat afterward).
File extension typos
Double-check the exact filename—case matters on systems like Linux. Accidental typos likexx.JSPorxx.jswill cause a 404, since Tomcat only recognizes lowercase.jspby default. HTML files are more forgiving because they're served as static content regardless of case (usually).Tomcat didn't detect the new file
If you added the JSP while Tomcat was running, try restarting the server. Some configurations don't auto-detect new JSP files on the fly. You can also verify ifautoDeploy="true"is set in the<Host>element of yourconf/server.xml—this enables automatic deployment of new files without a restart.File permission issues
Ensure the Tomcat process has read access to yourxx.jspfile. On Linux/macOS, runchmod 644 xx.jspto set read permissions, andchown tomcat:tomcat xx.jsp(adjust the user/group to match your Tomcat setup) to give the server ownership. On Windows, make sure the file isn't marked as read-only.
内容的提问来源于stack exchange,提问作者wuhui

