I have been trying to have a class call a JSP, and I have it working as
follows:
String str = someFunction(http://www.joe.com/InvoiceEmail.jsp);
so the class can use the output of the jsp. But this seems a bit wasteful of
resources, since the class and the jsp are on the same server. Is there an
easier way to call it?
Manish Pandit - 01 Nov 2006 02:51 GMT
> so the class can use the output of the jsp. But this seems a bit wasteful of
> resources, since the class and the jsp are on the same server. Is there an
> easier way to call it?
AFAIK, there is none. The lifecycle of a JSP (read servlet) is managed
by the container. The output that comes from a JSP hosted on a
container is the processed output. Invoking a JSP's method; even though
do-able, does not make sense as a JSP/servlet cannot exist without a
container - it needs a context, optional config, and HTTP
request/response/session.
-cheers,
Manish
Robert Mark Bram - 01 Nov 2006 06:00 GMT
> so the class can use the output of the jsp. But this seems a bit wasteful of
> resources, since the class and the jsp are on the same server. Is there an
> easier way to call it?
Instead you would want to encapsulate the functionality you need in a
java class and have your java class call it.. otherwise you are stuck
with being a client to the jsp, which means calling it in the same way
a web browser does.. through the URL.
Rob
:)
Mich - 01 Nov 2006 06:51 GMT
>> so the class can use the output of the jsp. But this seems a bit wasteful
>> of
[quoted text clipped - 6 lines]
> with being a client to the jsp, which means calling it in the same way
> a web browser does.. through the URL.
It is in a class right now; but having it in a JSP seems easier,
particularly if there is a lot of html in it.After trying a few ideas and
suggestions I gave up.
Robert Mark Bram - 01 Nov 2006 23:37 GMT
Hi Mich,
> It is in a class right now; but having it in a JSP seems easier,
> particularly if there is a lot of html in it.After trying a few ideas and
> suggestions I gave up.
If this is code that you have control over and the html is static (i.e.
doesn't use any JSP tags or JSTL etc), you can place the html in a
file. Then have your Java class read the file and do what it wants with
it.
Keep in mind that a JSP is just a fancy servlet: before a JSP is
executed it gets compiled into a servlet - a Java class that is called
through a servlet container that is in turn called from a web server.
What I am trying to say is that the usage 'paradigm' for JSPs and
Servlets involves them being called through a URL - a request/response
to/from some server.
Rob
:)
Mich - 02 Nov 2006 04:59 GMT
> Hi Mich,
>
[quoted text clipped - 16 lines]
> Rob
> :)
Rob, that is the way that I am going. I dropped out of being a software
developer some time ago and set up my own (successful) ecommerce site; so
this work is for my own benefit. I like the idea of using the http protocol
to build and easy low-tech distributed system. While everything is still on
the same server doing things this way does improve the modularity.
Much thanks.