wood burning stoves 2.0*
The moose likes Servlets and the fly likes Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Form" Watch "Form" New topic
Author

Form

Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
i make a simple servlet which send msg to www.SmsSite.com/SmsScript.asp it connects but not send msg.i am using this servlet to use in my computer for getting simple parameters and it is working fine. i think there is no problem with parameters values of mine and SmsSite cause i send msg using simple form from my desktop and it is working fine.pls help me.
it is working fine

<form method=POST action="http://www.SmsSite.com/SmsScript.asp" name="SMS">
<input type="hidden" name="email" value="SMS-Daemon@vxt.com">
<input type="hidden" name="recipient" value="sms@vxt.com">
<TEXTAREA NAME=MESSAGE ROWS=5 COLS=35></TEXTAREA>
<input type="text" name="PHONE" size="10" maxlength="8">
<INPUT TABINDEX="10" MAXLENGTH=3 SIZE=2 VALUE="150" NAME="smsLEFT" readOnly>
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Send" >
</form>
There is some problem in it.it connects but not send any msg.

import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Sms extends HttpServlet implements Runnable {
Thread thread;
URL url;
public void init() {
try {
System.out.println("Init");
thread=new Thread(this);
}
catch(Exception e){System.out.println("Error: "+e);}
}
public void doGet(HttpServletRequest req,HttpServletResponse res) {
thread.start();
}
public void run() {
try {
while(true) {
System.out.println("Sending Msg At : "+new Date());
sendSms();
thread.sleep(60*500);
}
}
catch(InterruptedException ie) {System.out.println("InterruptedException :"+ie);}
}
private void sendSms() {
try {
System.out.println("Connecting.....");
URL cellUrl = new URL("www.SmsSite.com/SmsScript.asp");
HttpURLConnection con = (HttpURLConnection) cellUrl.openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
String x ="email=SMS-Daemon@vxt.com&recipient=sms@vxt.com&MESSAGE=yahoo&PHONE=2142816&smsLEFT=150&SUBMIT=Send";
con.setRequestProperty("CONTENT_LENGTH", "" + x.length());
OutputStream os = con.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
osw.write(x);
osw.flush();
osw.close();
InputStream is = con.getInputStream();
System.out.println("Msg Has Been Sent");
}
catch(Exception ie) {System.out.println("InterruptedException :"+ie);}
}
}
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
why is the script called .asp when you have created a servlet? and why does the form submit to the asp file when it should be running the servlet? and why does the servlet connect to the same URL that the form does?
btw, having tried the smstext.asp or whatever URL, it gives me 404 - you can access a resource that is not there.


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
i am using .asp script because it is written by other person and i want to use it.and the url is wrong becaue it is just example.and i want to use form using servlet for example i want to submit form with the help of servlet.
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
Not sure why you would want to use the servlet as an intermediary, but you would need to have your web page call your servlet not the asp as mentioned earlier. You would then (inside the servlet) create an HTTP connection to a url (i.e. the asp page you want to call). It is easiest if you want to use a GET method because you can simply construct the url string to contain your parameters. If you do this make sure to url encode the data! If not there are methods that will allow you to post data to the connection, but I'm not familiar enough with them to discuss it without doing some research.
Hope this helps.
Byron Estes


Byron Estes<br />Sun Certified Enterprise Architect<br />Senior Consulant<br />Blackwell Consulting Services<br />Chicago, IL<br /><a href="http://www.bcsinc.com" target="_blank" rel="nofollow">www.bcsinc.com</a>
Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
HI
if want to submit simple form what would be the headers for it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form
 
Similar Threads
sending sms
Simple Problem
HttpURLConnection
Simple Problem
SMS port numbers (possibly FAO M. Yuan?)