You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tomcat 9.0.6无法提供应用目录内静态PDF文件问题求助

Hey there, let's troubleshoot why your PDF link isn't working in your Tomcat setup. Based on your environment (Ubuntu 16.04, Tomcat 9.0.6, Java 8) and directory structure, here are the most common issues and fixes:

The first thing to check is your PDF link in the JSP pages. Spaces in filenames can cause encoding issues in browsers.

  • Option 1: Rename User Doc.pdf to User_Doc.pdf or UserDoc.pdf (no spaces), then update your link to match, like:
    <a href="userDocs/User_Doc.pdf">View User Document</a>
    
  • Option 2: If you keep the space, encode it as %20 in your link:
    <a href="userDocs/User%20Doc.pdf">View User Document</a>
    

You can test this directly by typing the full URL into your browser (e.g., http://your-server:8080/RimWeighting/userDocs/User%20Doc.pdf). If this loads the PDF, your page's link path was the problem.

2. Verify File Permissions (Ubuntu-Specific)

Tomcat runs under a dedicated user (usually tomcat or www-data on Ubuntu), so it needs read access to your userDocs directory and the PDF file. Run these commands to fix permissions:

# Navigate to your app's directory
cd /var/lib/tomcat9/webapps/RimWeighting

# Give read/execute access to the directory
sudo chmod -R 755 userDocs/

# Give read access to the PDF file
sudo chmod 644 userDocs/User\ Doc.pdf

# Set the owner to Tomcat's user (adjust if your user is different)
sudo chown -R tomcat:tomcat userDocs/
3. Check for Web.xml Restrictions

If your WEB-INF/web.xml has a <security-constraint> configuration, it might be blocking access to the userDocs directory. Look for rules that restrict GET requests to static resources, and add an exception for userDocs/* if needed.

4. Confirm MIME Type Configuration

Tomcat should handle PDFs by default, but if the MIME type is missing, browsers won't render the file correctly. Check your Tomcat conf/web.xml for this entry:

<mime-mapping>
    <extension>pdf</extension>
    <mime-type>application/pdf</mime-type>
</mime-mapping>

If it's missing, add it and restart Tomcat.

Quick Test Flow
  1. Directly access the PDF via full URL in your browser. If it works, fix your page's link.
  2. If not, check file permissions first (Ubuntu often locks down file access).
  3. Finally, check web.xml for security rules and MIME type settings.

That should get your PDF loading in the browser!

内容的提问来源于stack exchange,提问作者Robert P.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:52:43