wood burning stoves*
The moose likes JSP and the fly likes Calling a JSP from a Java class on the client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Calling a JSP from a Java class on the client " Watch "Calling a JSP from a Java class on the client " New topic
Author

Calling a JSP from a Java class on the client

Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hi there,

I am trying to call a JSP page from a class sitting on client machine. Here is the scnerio:

o I have an OC4J instance (or any web/app server for that matter).
o There is a JSP page (say, test.jsp) deployed as part of a web app.
o I have an application or a Java class on a client machine.
o I want to invoke the test.jsp from this Java class and pass it some
binary data.

Any ideas on how to achieve this? I am not if I have been able to explain my problem clearly. If not, please let me know if there are any questions.

TIA,
Saeed
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61094
    
  66

Originally posted by Saeed Amer:
and pass it some binary data.


This is the part that may be an issue. JSPs aren't "called" in the same way as methods. They are invoked via an HTTP request. So there's no "passing" of data except by using the HTTP protocol.

So by "pass it some binary data" are you talking about a file upload?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Thank you for your response, Bear!

I understand that JSPs are not called like methods and I thought of sending the binary data as a param (not sure if this is a good idea, or even a right thing to do).

I am looking at the "HttpURLConnection" but not sure yet if I'll be able to accomplish what I mentioned in original post.

> So by "pass it some binary data" are you talking about a file upload?
Yes, this is a "File Upload" task. The application is "Oracle Forms 10g application" running on Oracle App Server 10g and user has to be able to select a file from his/her local hard disk and send send it to an another application (Content Manager - running on some other app server) for storing.



Saeed
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61094
    
  66

Originally posted by Saeed Amer:
I thought of sending the binary data as a param (not sure if this is a good idea, or even a right thing to do).


It's not possible. Parameters must be text.

Rather, you need to send a multi-part request that contains the data and necessary headers, in the same way that an HTML input element of type "file" would. Formattng such a request could be a bit tricky.


I am looking at the "HttpURLConnection"


That would be one way to do it. But you'd be reponsible for a lot of detail in generating the request. I'd suggest taking a look at the Jakarta HttpClient project before diving off into perhaps re-inventing the wheel.
[ November 16, 2006: Message edited by: Bear Bibeault ]
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hi Bear,

Thanks again!

It's not possible. Parameters must be text.


Please forgive me for my ignorance but I read some where that through POST request, binary data can be sent (now, I am not totaly sure of the context - maybe it was regarding a Servlet, though a JSP also ultimately runs as a servlet). That was in my mind when I though on these line. How can I use the "POST" method to send data to JSP (if at all)?

OK, as you have suggested, I'll look at the Jakarta HttpClient stuff.

Thank you once again!

Saeed
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61094
    
  66

Originally posted by Saeed Amer:
that through POST request, binary data can be sent


Yes, by way of the multi-part request that I already mentioned.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
If you're wanting to send binary data via HTTP from a java class, I would recommend you look at the jakarta commons HttpClient library.
http://jakarta.apache.org/commons/httpclient/

Pro: It will help you do the upload with a minimum of fuss.
Con: The support libraries you need to install for it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61094
    
  66

Originally posted by Stefan Evans:
If you're wanting to send binary data via HTTP from a java class, I would recommend you look at the jakarta commons HttpClient library.


Yes, as I had already recommended.
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Thank you Bear & Stefan!

I am working on it using HttpClient as suggested... I hope I'll get it done...

Regards,
Saeed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling a JSP from a Java class on the client