希望可以有人帮帮我。尝试显示JSP页面时出现此错误:
18:41:22,674 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.io.FileNotFoundException: http:\localhost:8080\leopardcreek\xxxx.pem
(The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
我知道路径正确,文件在那里。该URL中什么语法不正确?
我的Java部分:
URL myURL = new URL("http://localhost:8080/leopardcreek/xxxx.pem");
req.setAttribute("keyUrl", myURL);
JSP:
<%
String keyUrl = request.getAttribute("keyUrl").toString();
InputStream inStream = new FileInputStream(keyUrl);
%>
最佳答案
您需要将其读取为URLStream
String keyUrlString = request.getAttribute("keyUrl").toString();
URL keyURL = new URL(keyUrlString);
BufferedReader in = new BufferedReader(
new InputStreamReader(keyURL.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
//process
注意:完全不建议将此代码放在视图模板(.jsp)上