A java class invokes a JSP?

Discussion in 'Java' started by Mich, Nov 1, 2006.

  1. Mich

    Mich Guest

    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?
    Mich, Nov 1, 2006
    #1
    1. Advertising

  2. > 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
    Manish Pandit, Nov 1, 2006
    #2
    1. Advertising


  3. > 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
    :)
    Robert Mark Bram, Nov 1, 2006
    #3
  4. Mich

    Mich Guest

    "Robert Mark Bram" <> wrote in message
    news:...
    >
    >> 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.



    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.
    Mich, Nov 1, 2006
    #4
  5. 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
    :)
    Robert Mark Bram, Nov 1, 2006
    #5
  6. Mich

    Mich Guest

    "Robert Mark Bram" <> wrote in message
    news:...
    > 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
    > :)


    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.
    Mich, Nov 2, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don
    Replies:
    0
    Views:
    4,329
  2. Replies:
    4
    Views:
    403
    Salt_Peter
    Oct 12, 2006
  3. Oliver Bleckmann
    Replies:
    4
    Views:
    299
    Gavin Deane
    Dec 1, 2006
  4. Yogi
    Replies:
    3
    Views:
    1,640
    Roedy Green
    Nov 3, 2007
  5. Hoss Spence
    Replies:
    3
    Views:
    3,875
    ankit200490
    Feb 29, 2012
Loading...

Share This Page