Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java Server Pages

0 views
Skip to first unread message

Michael

unread,
Jun 24, 2002, 5:38:12 PM6/24/02
to
Greetings,

Can a Java Server Page create a jpeg from an external Java Bean?

David Off

unread,
Jun 24, 2002, 5:49:58 PM6/24/02
to
Michael wrote:
> Greetings,
>
> Can a Java Server Page create a jpeg from an external Java Bean?

Yes... well your Java Bean can return a JPEG image as data. You would
need to reference the JSP with the <img src="xyz.jsp"> tag and the JSP
would have to set the image/jpeg mime type. You then just write the
jpeg data to the output stream.

David

Michiel Konstapel

unread,
Jun 24, 2002, 6:43:02 PM6/24/02
to
"David Off" <david.off_d...@voila.fr> wrote in message
news:3D179406...@voila.fr...

You *really* don't want to do that. JSPs are for writing character data,
they always use a Writer to produce their output. JPEGs are binary data.
Putting that through a Writer (which does character encoding) won't work. If
you want to generate binary data, just use a servlet and its OutputStream.
Michiel


Aaron Porter

unread,
Jun 24, 2002, 9:11:43 PM6/24/02
to
"Michiel Konstapel" <a...@me.nl> wrote in message
news:WfNR8.337586$i6.22...@amsnews02.chello.com...

JSP works just fine. Just make sure you don't use the writer (out) at all,
otherwise you'll get warnings and/or errors. Make a call to
response.getOutputStream and write to that. Also, make sure you don't have
anything on the page outside of the JSP tags (including \r\n) as that will
automatically cause the writer to be used.

I can provide a sample if you're interested.

Aaron


Chris Smith

unread,
Jun 24, 2002, 9:45:05 PM6/24/02
to
Aaron Porter wrote ...

> JSP works just fine. Just make sure you don't use the writer (out) at all,
> otherwise you'll get warnings and/or errors. Make a call to
> response.getOutputStream and write to that. Also, make sure you don't have
> anything on the page outside of the JSP tags (including \r\n) as that will
> automatically cause the writer to be used.
>
> I can provide a sample if you're interested.

Why?

At least in a quick skim, I see nothing in the JSP specification
requiring that a generated JSP not call getWriter() if there is no
generated data... so I wouldn't depend on this working, regardless of
whether or not it does in the container you tested in.

In general, JSPs work well in environments that are producing *ML... by
which I mean HTML, XML, etc... that is, tagged text where whitespace is
generally irrelevant. Trying to fit it into other situations is
possible, but it's generally an indicator that there's a better way of
accomplishing that goal.

Chris Smith

Michael

unread,
Jun 25, 2002, 12:06:42 PM6/25/02
to
"Aaron Porter" <apo...@cyberradio.com> wrote in message news:<SmPR8.109$yi.1...@news.uswest.net>...

Aaron,

I would be interested in a sample

Thanks,

Michael

Aaron Porter

unread,
Jun 26, 2002, 2:13:35 PM6/26/02
to

"Michael" <mjohn...@yahoo.com> wrote in message

>
> Aaron,
>
> I would be interested in a sample
>
> Thanks,
>
> Michael

Here you go. This example requires JDK 1.4 for the ImageIO libraries. You
use other libraries if you don't have 1.4 or if you want to create GIFs.

Make sure you don't have an extra line break before or after the code below.

Aaron


<%@
page import="javax.imageio.*"
%><%@
page import="java.awt.image.*"
%><%@
page import="java.awt.*"
%><%

BufferedImage image = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);

Graphics2D graphics = image.createGraphics();

graphics.setColor(Color.white);
graphics.fillRect(0, 0, 100, 100);

graphics.setColor(Color.black);
graphics.drawLine(50, 0, 50, 100);
graphics.drawLine(0, 50, 100, 50);

ImageIO.write(image, "jpeg", response.getOutputStream());

%><%!
static
{
ImageIO.setUseCache(false);
}
%>


Kevin Docherty

unread,
Jul 1, 2002, 10:09:32 AM7/1/02
to
Hi,

I was wondering if anyone could help.....

Chapter 20 of Aneesha Bakharia's Java Server Pages fast & easy web
development has a shopping cart facility. I have written thhe code as it is
written and have indeed used the code of the cd (to avoid mistakes). There
is one class used called Product and one Java bean called ShoppingCart .When
running the JSPs my database catalog appears as planned but when I go to
click on the 'BUY' link (to add the product to my shopping basket) I get the
following message:

500 Internal Server Error
/DisplayCatalog.jsp:

javax.servlet.ServletException: Exception thrown on line '57' from page
'C:\\Program
Files\\Allaire\\JRun\\servers\\default\\default-app\\DisplayCatalog.jsp'.
java.lang.IllegalAccessError: try to access class Product from class
jrun__DisplayCatalog2ejsp13
at
jrun__DisplayCatalog2ejsp13._jspService(jrun__DisplayCatalog2ejsp13.java:104
)
at allaire.jrun.jsp.HttpJSPServlet.service(../jsp/HttpJSPServlet.java:40)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at
allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatc
her.java:34)
at allaire.jrun.jsp.JSPServlet.service(../jsp/JSPServlet.java:175)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at
allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDis
patcher.java:88)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:330)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:107)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)


Why can't I access the Product class?


Kevin Docherty

unread,
Jul 1, 2002, 10:12:37 AM7/1/02
to
test
"Kevin Docherty" <Kevin.D...@nospambtinternet.com> wrote in message
news:afpnqr$s63$1...@venus.btinternet.com...
0 new messages