A java class invokes a JSP?

M

Mich

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?
 
M

Manish Pandit

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
 
R

Robert Mark Bram

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
:)
 
M

Mich

Robert Mark Bram said:
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.


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.
 
R

Robert Mark Bram

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
:)
 
M

Mich

Robert Mark Bram said:
Hi Mich,


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
:)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,585
Members
45,082
Latest member
KetonaraKetoACV

Latest Threads

Top