Susan, I wrote a applet that uses a servlet and used the following method to pass the form data to the applet. What the class does is takes the data passed to it by using a property and url encodes it, it then appends the jsessionid if it needs to and posts it to the servlet.
Hope it help. Schalk van Jaarsveld SCJP, MCSD, MCP Cellular: +27 (0) 82 296 8748 Phone: +27 (0) 11 763 5095 Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> package intranet.comm; import java.io.*; import java.net.*; import java.util.*; import intranet.graphics.*; public class IPAHttpRequest { URL url = null; //to manipulate graphical aspects of SwingSet2 we need a reference there, //this reference is also used to get values like the sessionid ect... private SwingSet2 swingset2 = null; /** *This constructor saves a reference to the URL of the servlet to invoke */ public IPAHttpRequest(URL servletURL) { System.out.println("servletURL = " + servletURL); url = servletURL; } /** This method parses the Properties object that is passes in and sends this data *to the servlet in its request. It returns the servlets response to the applet. * *@param An InputStream that represents the servlets response; *@param props The name/value pairs that are stored in a Properites object. */ public InputStream processPostRequest(Properties props) throws IOException { String paramString = ""; //parse the Properties object and encode the name/value //pairs so they can be sent correctly to the servlet as POST data. if (props != null) { StringBuffer sb = new StringBuffer(); Enumeration members = props.propertyNames(); String propName = null; String propValue = null; System.out.println("Before the sessionid"); String sessionid = swingset2.getSessionid(); System.out.println("The sessionid is " + sessionid); //if the sessionid is not null, meaning there is a valid session we //use url rewritting. if (sessionid == null) { while (members.hasMoreElements()) { propName = (String) members.nextElement(); propValue = props.getProperty(propName); sb.append(URLEncoder.encode(propName) + "=" + URLEncoder.encode(propValue)); if (members.hasMoreElements()) { sb.append("&"); } } }else { while (members.hasMoreElements()) { propName = (String) members.nextElement(); propValue = props.getProperty(propName); sb.append(URLEncoder.encode(propName) + "=" + URLEncoder.encode(propValue)); if (members.hasMoreElements()) { sb.append("&"); } } sb.append("&jsessionid=" + URLEncoder.encode(sessionid)); } paramString = sb.toString(); System.out.println("paramString: " + paramString); } URLConnection con = url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); //Set the general request property con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); //write the properties out as POST data DataOutputStream out = new DataOutputStream(con.getOutputStream()); System.out.println("out.writeBytes(paramString)"); out.writeBytes(paramString); out.flush(); out.close(); //return the servlets response to the applet return con.getInputStream(); } public void setSwingSet2(SwingSet2 swingset2) { this.swingset2 = swingset2; } } -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 09, 2001 9:04 PM To: JRun-Talk Subject: RE: RE: Way to post form data without a form? You could always just do it the easy way and generate a page with just a form and the form data filled in then put a javascript at the bottom of the page that submits the form. The user doesn't notice and it's simple. Travis ---- Original Message ---- From: Mark Phelps <[EMAIL PROTECTED]> Sent: 2001-10-09 11:16:07.0 To: JRun-Talk <[EMAIL PROTECTED]> Subject: RE: Way to post form data without a form? Try using the HttpURLConnection class in the java.net package. Before opening a connection you need to call the setRequestMethod() function and set the method to POST. -----Original Message----- From: Susan M. Orndorff [mailto:[EMAIL PROTECTED]] Sent: Monday, October 08, 2001 12:32 PM To: JRun-Talk Subject: Way to post form data without a form? I am using an applet to call a servlet named OrderPage which returns an html page. To do this I am using URL newUrl = new URL("https://hostname.com/store/OrderPage?Item=teaCustomer=Nancy") getAppletContext().showDocument(newUrl, "_self"); When I do this, the parameter string (?Item=teaCustomer=Nancy) shows in the address window. I do not want these parameters to show. I have been told there is a way to post data like a form would, but without using a form, that is, to do it automatically from within the program, without ANY user interaction. Does anyone know how this is done? Thanks for any help... Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=sts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get the mailserver that powers this list at http://www.coolfusion.com Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
