• 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

Form

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);}
}
}
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raja Islam
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Raja Islam
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
if want to submit simple form what would be the headers for it.
reply
    Bookmark Topic Watch Topic
  • New Topic