Jsp [java.lang.IllegalStateException:getOutputStream()已为此响应调用]
这是我的JSP代码。几天前,它运转良好。但我现在无法查看pdf文件Jsp [java.lang.IllegalStateException:getOutputStream()已为此响应调用],jsp,Jsp,这是我的JSP代码。几天前,它运转良好。但我现在无法查看pdf文件 <% String email = (String) session.getAttribute("email"); %> <% connection = DriverManager.getConnection(connectionUrl+database, userid, password); String sql ="select resume from signup where email = ?"; ps
<% String email = (String) session.getAttribute("email"); %>
<%
connection = DriverManager.getConnection(connectionUrl+database, userid, password);
String sql ="select resume from signup where email = ?";
ps = connection.prepareStatement(sql);
ps.setString(1,email);
resultSet = ps.executeQuery();
while(resultSet.next()){
byte [] resumeBytes = resultSet.getBytes("resume");
%>
<!DOCTYPE html>
<html>
<head>
<title>Your Resume</title>
</head>
<body>
<%
DataOutput dataOutput = new DataOutputStream(response.getOutputStream());
response.setContentType("application/pdf");
for(int i = 0; i < resumeBytes.length; i++){
dataOutput.write(resumeBytes[i]);
}
}
%>
你的简历
“已为此响应调用getOutputStream()”是异常情况。请帮我解释一下我所知道的 **HTTP的基本规则:一个请求,一个响应。 您只能向请求发回一件事。HTML页面,或 PDF文档、图像或。。。。具体来说,您不能发送HTML 页面和PDF文档。如果您已经获得了 writer/outputstream,因为您应该只获得其中一个** 由于您已将PDF发送回浏览器,我无法使用guest。您的execute()方法应该返回'null'来告诉Struts不要这样做 最好在servlet中完成,将其转发到新的jsp页面,并添加try-And-catch块,最后再添加block,或者您可以在try-And-catch中使用装饰图案,这样当流结束时,它将自动关闭所有打开的资源 我希望我能帮上忙