• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling a URL via HttpClient

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi - I am new to java.

I have a JSP page that needs to make a URL Get Post and get the response back.
I was thinking of putting the code in a Java Bean that is accessible via the JSP Page.

I can call the MultiThreadedHttpConnectionManager and then
client = new HttpClient();
client.executeMethod(method)
method.getResponseBody

This code is to execute the Get URL and retrieve it's return value.

The question that I have is can I put this code in a Java Bean or do I need to put it in a Servlet ?

Also can I write to a log file from within a Java Bean set property method?

Can I have a method in a Java Bean and how do I call the method from JSP?

Thanks very much.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leo Cono wrote:I have a JSP page that needs to make a URL Get Post and get the response back.


A GET or a POST? It can't be both.

I can call the MultiThreadedHttpConnectionManager and then
client = new HttpClient();


Why? Is the resource to be accessed in another web application?

Can I have a method in a Java Bean and how do I call the method from JSP?


That greatly depends upon what you mean by "call". The term is quite ambiguous in this context.
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to make a URL Get call to an external web application and get a response back.

I want to make the URL Get call within a method in a java bean that is callled from a jsp page.
Is this possible or do I need a servlet?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any Java class could make the URL call - unless there is some SecurityManager preventing it.

Be sure you handle all the possible error conditions.

A big advantage of using a separate class is that you can test it outside the servlet environment - why not just put in a main() method that gets the url from the command line.

Bill
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am unfamiliar with creating a method inside a bean and callling it from JSP.

Do I create a set property and treat it like a method? or is there a way to create methods and call them from jsp?

Thanks very much.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are writing modern JSPs using SJTL and EL there is no way to call general methods, as that is something expected to be handled by page controller servlets. What is it about this that forces you to do it from a JSP?
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp page is collecting user registration information and I want to send this registration information data to another web site via url get execution.
May you please advise the best way to do this?

Thanks very much.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you want to gather the info after the user has entered info?

If so, you don't want to call anything from the JSP which gets executed before the page is ever even sent to the user.

This is something you'd do in the servlet controller to which the form is submitted after the user has filled out the info.
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp page does a postback to itself.
1.) user enter registration data into a jsp page
2.) jsp <% %> section captures the data entered into the form.
3.) jsp calls a bean method to send captured data via URL Get to an external web site
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leo Cono wrote:The jsp page does a postback to itself.
1.) user enter registration data into a jsp page
2.) jsp <% %> section captures the data entered into the form.
3.) jsp calls a bean method to send captured data via URL Get to an external web site



That's a really out-dated and poor practice. You might want to consider bringing your application up to modern standards and practices.

You'll also find that it prevents you from taking best advantage of modern techniques.

Maybe you'll find this article helpful.
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok but this is not my code and I can not rewrite the java 1.1 architecture.

May you please show me an example of jsp executing a "url get" to an external web site?

Thanks very much.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does this have to do with Java 1.1?

If you are working with older code, it'd best to follow the precedent of that code unless you plan a major refactor.

Are there no examples within the code of making calls to bean methods?

And...
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I have to work with the code I have.

I decided to not put the code in a bean.

From the jsp scriplet, I want to make a URL Get call to an external web site.

Do you know how to do this?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes no sense. Even in an old scriptlet environment it's still easier to call a method (one line of Java) than to put a bunch of code in the JSP. Why do you think that's hard?

Just call the code from the JSP scriptlet code. What's the issue?

 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So appearantly you do not know how to do this.

Does anybody else know how to make a URL Get call to an external web site from a jsp scriplet?

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leo Cono wrote:So appearantly you do not know how to do this.


Apparently you learned nothing from the parable I linked to.

So what is "this"? The use of HttpClient, or how to call a method? You've been very unclear on exactly what you are having trouble with.

I asked for clarification and all I get is lip service? Antagonizing people who are trying to help you is not a winning strategy -- I suggest you re-evaluate your attitude and approach.
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are really trying to help then please give me an answer on how to make a URL get call to an external web site from a jsp page.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to cooperate in order to get help; not exude attitude issues.

Again I ask, what aspect are you having problems with? HttpClient? Calling methods? What?

Also, if you are just trying to import text (you haven't really said) why don't you just use <c:import> and be done with it?
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpClient
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK then. This has nothing much to do with JSP them. If you are using scriptlets, the the Java code would be the same as you would write anywhere else.

This post has been moved to a forum more appropriate for dealing with HttpClient questions.

I've also adjusted the title a bit to help people find your question.
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Very Much
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait; now *I'm* confused.

Have you looked at the HttpClient example code? What's going wrong when you're making the request?
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where can I find HttpClient example code?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On its website? I mean, that's where I'd look first, anyway. Seems logical.

http://hc.apache.org/httpclient-3.x/tutorial.html
 
Leo Cono
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic