• 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

Servlet Communication

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my scenario...
I have a form that submits to a servlet. The servlet then processes my request and redirects me or whatever it does to a new page.
Supoose I want to submit things to that servlet but I want the ability to do one or both of the following...
Submit a request to the form w/o using a form and not have me redirect me anywhere...
So I guess I want to create some java code that sends a request, and when I send it that is it it doesnt take me anywhere. I dont have access to the servlet so I cant change it or even know how it works other than what elements the form has.
Please help!
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi anthony
can u describe ur situation more? because there are ways to do "auto form submission".
1. if u have access to write an HTML which can get submitted to the destination servlet then u can write document.YourFormName.submit() on onLoad() method of the BODY tag and fill the form parameters already (hard-coded) so when u open the HTML having that form it will get automatically submitted....
2. if u have to write the multiple set of such forms (to automate the bulk submission) then,
-u can write a jsp in which u will embed a form,
-pass ur form input parameters to that JSP which will fill the form paramters
-and have the document.YourFormName.submit() on onLoad() the same way as in option-1 above.
3. if u completely want to get rid of this kind of HTML or JSP then u can write a java program which is getting input parameters from some stream and then use the following code to prepare the request query string that is to be passed to the servlet and then use URLConnection to the servlet to write to its outputstream,
public void sendPostMessage(Properties p) throws Exception{
String argString="";
if ( p != null ) {
argString = toEncodedString(p);
}
}
public String toEncodedString(Properties p) {
StringBuffer bf = new StringBuffer();
Enumeration names = p.propertyNames();
while(names.hasMoreElements()) {

String name = (String)names.nextElement();
String value = p.getProperty(name);

bf.append(URLEncoder.encode(name)+"="+URLEncoder.encode(value));
if ( names.hasMoreElements() )
bf.append("&");
}
return bf.toString();
}
(if u do it this way then the servlet will recieve the request in its doPost method)
hope this was little helpful.
let me know if i missed ur point anywhere...
regards
maulin
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the last one is what I wpuld like to do. Where is my Properties p to come from?

I will put this in a servlet I guess...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic