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?
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?
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
1
posted
0
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.
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
Joined: Sep 06, 2009
Posts: 13
posted
0
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?
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
Joined: Sep 06, 2009
Posts: 13
posted
0
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
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.
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
Joined: Sep 06, 2009
Posts: 13
posted
0
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?
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
Joined: Sep 06, 2009
Posts: 13
posted
0
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.