You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Sihong Fan <fa...@yahoo.com> on 2004/05/21 19:10:26 UTC
non-text in JSP(mixed content type in portlet)
I want hide(security reason) a group of static PDF in
jetspeed. So I read and write the PDF in jsp. This jsp
page can read and write jsp out side jetspeed. But
after I put it into jetspeed. It give me 'getWriter()
has already been called for this response ' error.
Does any one know how to solve the problem?
Here is my jsp
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%
OutputStream o = response.getOutputStream();
response.setContentType("application/pdf");
File f = new File("pdf/test2.pdf");
InputStream is = f.toURL().openStream();
byte[] buf = new byte[32 * 1024];
int nRead = 0;
while( (nRead=is.read(buf)) != -1 ) {
o.write(buf, 0, nRead);
}
%>
Thanks a lot
__________________________________
Do you Yahoo!?
Yahoo! Domains � Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org
Re: non-text in JSP(mixed content type in portlet)
Posted by Raphaël Luta <ra...@apache.org>.
Le 21 mai 04, à 19:10, Sihong Fan a écrit :
> I want hide(security reason) a group of static PDF in
> jetspeed. So I read and write the PDF in jsp. This jsp
> page can read and write jsp out side jetspeed. But
> after I put it into jetspeed. It give me 'getWriter()
> has already been called for this response ' error.
>
> Does any one know how to solve the problem?
>
> Here is my jsp
>
> <%@ page import="java.io.*" %>
> <%@ page import="java.net.*" %>
> <%
> OutputStream o = response.getOutputStream();
> response.setContentType("application/pdf");
> File f = new File("pdf/test2.pdf");
> InputStream is = f.toURL().openStream();
> byte[] buf = new byte[32 * 1024];
> int nRead = 0;
> while( (nRead=is.read(buf)) != -1 ) {
> o.write(buf, 0, nRead);
> }
> %>
You can't mix 2 content-types in a single HTTP response. Your portlet
needs to output
a valid HTML markup that the browser will then execute to to request the
PDF.
portlet sends:
document.location.href="http://myportal/jetspeed/portal/layout/raw.jsp/
template/sendPDF.jsp"
and put your sendPDF.jsp in webapp/WEB-INF/templates/jsp/screens/
you'll also need a webapp/WEB-INF/templates/jsp/layouts/raw.jsp:
<%
String screenJsp = (String)request.getAttribute("screenJsp");
%><jsp:include page="<%= screenJsp %>" flush="true" />
--
Raphaël Luta - raphael@apache.org
Apache Jetspeed - Enterprise Portal in Java
http://portals.apache.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org