gpt4 book ai didi

java - getpathtranslated 返回 null

转载 作者:行者123 更新时间:2023-12-01 04:28:02 26 4
gpt4 key购买 nike

我尝试实现方法getPathTranslated()但总是返回null的事情,这是我使用的方法:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FileLocation extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//response.setContentType("text/html;charset=UTF-8");
response.setContentType("text/plain");
PrintWriter out = response.getWriter();

if (request.getPathInfo() != null) {
out.println("The file \"" + request.getPathInfo() + "\"");
out.println("Is stored at \"" + request.getPathTranslated() + "\"");
} else {
out.println("Path info is null, no file to lookup");
}
}
}

最佳答案

如果您尝试检索与 URL 路径相对应的文件系统路径,请尝试 getServletContext().getRealPath("your_path")

关于java - getpathtranslated 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18295108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com