This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I am sending a user query request to a Vendor's URL to receive a query reply back. I am writing a servlet that writes a HTML form that goes to the Vendor's URL. I've dealt with servlets that are initiated by a user and output HTML where the user submits the form data. Our situation is different. First, we have to somehow initiate the Servlet from a class. Second, the html must somehow be auto-submitted (without user-interaction). All this must be done behind the scenes without any user interaction. Can anyone help? Sandy
Hi, I'm not sure whether there is a better or more efficient way to do it but we created a URL object on the required query string in the class and then opened the connection using the URLConnection object. We then read the response from the connection. We used this to lookup a users address by the postcode. An example of the code is below I hope this helps Cheers, Steve
Note that when you open a URL with a string starting "http://" you actually get a HttpURLConnection object. This allows you to set all of the regular HTTP headers in case the URL you are sending to requires them. Bill