post your comment   print   send to a friend
Rate:  38% | Views: 866
Question categories:  Java

How do I access Servlets or CGI programs from Java?

Using the QUERY method (i.e., the calling parameters encoded in the URL), it is simple to access Servlets or CGI programs from Java:

URLConnection connect ( new URL("http:\\me\mycgi.sh") ).getConnection();
PrintStream ps = new PrintStream(connect.getOutputStream());
connection.setdoOutput(true)// defaults to false
ps.print(myPostData);
ps.close() // very important to close before reading
InputStream is = new PrintStream(connect.getInputStream());
// read the results

NOTE: URLConnection() is an abstract class whose sub-class is usually supplied by the environment (browser). Some browsers allow output without calling "doOutput(true)," which violates the Java spec and may be confusing when code works in one place and not the other.

Customer Feedback
Rate:  38% | Views: 866 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Server Hosting | Dedicated Server Host    Back to serch results
Browse the Base
Knowledge Base
Web Design
  Do It Yourself
    Java
Messages
 

$75 Free Google AdWords

Free $75 Google AdWords when you sign up for WebImage! Target by location, create your own, or let Google create your ads for you. Check out http://www.aplus.net/google.html to see how AdWords works for you.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. My applet computes its window size. Can I resize it in the browser?
 
2. How do I communicate between my applets in the same browser?
 
3. How do I force the browser to reload my Java classes without exiting Navigator?
 
4. Why does my java console show an applet is pruned?
 
5. Why do I get a JavaScript error using a String returned from a Java applet to index an array?
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest