我尝试实现方法 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");
}
}
}