This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Communication" Watch "Servlet Communication" New topic

Servlet Communication

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
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!
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
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);

if ( names.hasMoreElements() )
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...
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
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...
I agree. Here's the link:
subject: Servlet Communication
It's not a secret anymore!