• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Sending SMS from server to mobile with JSP

Hey Experts,
I'm trying to send a sms from my website to a user registered in the database.
On my first page (sendsms.jsp) i have a drop down menu that Selects all the Users from the MySQL database. And then a submit button to call the jsp page (smssent.jsp) necessary to perform the sending of the sms message. By the way I'm doing this with clickatell if anyone has used it before. I select one user from this drop down and hence it gets sent to one user.
Not too sure if I should have posted this here or in the other section ... anyway

What I have so far for the smssent.jsp is as follows:

<%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=&password=");    
statement = connection.createStatement();

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName= method="post" action="http://api.clickatell.com/http/sendmsg?user=&password=&api_id=&to=&text=Meet+me+outside");

user = "";
password = "";
api_id = "";
baseurl ="http://api.clickatell.com";
text = urlencode("Hi from ...");
to = Phone;

                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;
 <%
{
    connection.close();
}

%>  

Problem is sending it. What my intention is to select the User's phone no. from the database that equals to the member selected from the drop down menu. And to have a pre defined messsage like, "Hi bla bla bla". I probably need to have variables in there for some of the values?
0
acslater
Asked:
acslater
  • 17
  • 15
  • 2
1 Solution
 
KuldeepchaturvediCommented:
well.. this is not how you we can accomplish it...
here are the things that you will have to change in this jsp..

<%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=&password=");    
statement = connection.createStatement();

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("User"));

user = "";
password = "";
api_id = "";
baseurl ="http://api.clickatell.com";
text = urlencode("Hi from ...");
to = Phone;
if(rs.next())
{
user =rs.getString("user");
password = rs.getString("password");
api_id = "";
baseurl ="http://api.clickatell.com";
text = urlencode("Hi from ...");
to =rs.getString("phone");
}
%>
<html>
<body onload=document.forms[0].submit();>
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=&to=<%=to%>&text=Meet+me+outside">
</form>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  

0
 
acslaterAuthor Commented:
ok changed to the above and am getting 18 errors now.
the last part says:

Note: /home/combcdte/tomcat/work/smssent_jsp.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
18 errors

all the errors say >> cannot resolve symbol
0
 
RaftorCommented:
set up an account with vgsmail.com and they will give u bout 11 free texts before you have to pay them, but its enough for testing.

The sms interface has the URL http://www.vgsmail.com/cgi/sendsms.cgi and requires the following parameters (either as GET or POST methods):

userid ---- Your vgsmail userid
password ---- Your vgsmail password
to ---- The destination number
from ---- The originator ID of the message (must be enabled on your account)
text ---- The text you wish to send

So, using the GET method in the address bar when u get ur user id and password just but them in this below and the number and it should work,

http://www.vgsmail.com/cgi/sendsms.cgi?userid=MYUSERID&password=MYPASSWORD&to=353879248633&text=this+is+a+test 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
acslaterAuthor Commented:
I've set up an account with clickatell, its the same as the rest. I can post a message in the url so thats working fine so not much point in joining up with someone else aswell. I'm just trying to integrate it so that i can send a message to a user in the database by clicking a button ...
0
 
KuldeepchaturvediCommented:
okay u will get can not resolve errors because none of our variables are declared.

<%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=&password=");    
statement = connection.createStatement();

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("User"));

String user = "";
String  password = "";
String  api_id = "";
String  baseurl ="http://api.clickatell.com";
String  text = urlencode("Hi from ...");
String  to = Phone;
if(rs.next())
{
user =rs.getString("user");
password = rs.getString("password");
api_id = "";
baseurl ="http://api.clickatell.com";
text = urlencode("Hi from ...");
to =rs.getString("phone");
}
%>
<html>
<body onload=document.forms[0].submit();>
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=&to=<%=to%>&text=Meet+me+outside">
</form>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  

0
 
acslaterAuthor Commented:
I've declared all the strings and values in ...

String user = "";
String  password = "";
String  api_id = "";
String  baseurl ="http://api.clickatell.com";
String  text = urlencode("Hi from ...");
String  to = Phone;

"Phone" is the attribute in the db, and should be ok.
Does the form below look correct? Still getting errors for this.

<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%api_id%>&to=<%to%>&text=<%text%>">
0
 
KuldeepchaturvediCommented:
you are missing some = signs in the form..

<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%api_id%>&to=<%to%>&text=<%text%>">
 
shd be
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>">
 
 
 
 
 
0
 
acslaterAuthor Commented:
ok I changed that bit and now saying ..

org.apache.jasper.JasperException: Unable to compile class for JSP

.......
.......
.......


root cause

java.lang.ClassNotFoundException: org.apache.jsp.smssent_jsp

0
 
KuldeepchaturvediCommented:
whats the full error trace??
It looks like its not finding some class that needs to be there....
0
 
acslaterAuthor Commented:
The full error trace is ...

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP
      at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:500)
      at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:150)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:195)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:457)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:576)
      at java.lang.Thread.run(Thread.java:534)


root cause

java.lang.ClassNotFoundException: org.apache.jsp.smssent_jsp
      at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:209)
      at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:131)
      at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:497)
      at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:150)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:195)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:457)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:576)
      at java.lang.Thread.run(Thread.java:534)

0
 
KuldeepchaturvediCommented:
whats the name of your jsp file? it should be smssent.jsp ( all lower cases)...
0
 
acslaterAuthor Commented:
i changed it / renamed it because it wasn't registering properly.
I'm getting 3 errors now ...

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 93 in the jsp file: /sent.jsp

Generated servlet error:
    [javac] Compiling 1 source file

/home/combcdte/tomcat/work/sent_jsp.java:174: cannot resolve symbol
symbol  : method urlencode (java.lang.String)
location: class org.apache.jsp.sent_jsp
String  text = urlencode("Hi from ...");
               ^
An error occurred at line: 93 in the jsp file: /sent.jsp

Generated servlet error:
/home/combcdte/tomcat/work/sent_jsp.java:175: cannot resolve symbol
symbol  : variable Phone
location: class org.apache.jsp.sent_jsp
String  to = Phone;
             ^

An error occurred at line: 93 in the jsp file: /sent.jsp

Generated servlet error:
/home/combcdte/tomcat/work/sent_jsp.java:182: cannot resolve symbol
symbol  : method urlencode (java.lang.String)
location: class org.apache.jsp.sent_jsp
text = urlencode("Hi from ...");
       ^
Note: /home/combcdte/tomcat/work/sent_jsp.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
3 errors
0
 
KuldeepchaturvediCommented:
urlencode is not a method so you can not use it as is...
<%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=&password=");    
statement = connection.createStatement();

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("User"));

String user = "";
String  password = "";
String  api_id = "";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi from ...";
String  to = "";
if(rs.next())
{
user =rs.getString("user");
password = rs.getString("password");
api_id = "";
baseurl ="http://api.clickatell.com";
text = "Hi from ...";
to =rs.getString("phone");
}
%>
<html>
<body onload=document.forms[0].submit();>
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=&to=<%=to%>&text=Meet+me+outside">
</form>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  

This jsp shd atleast compile...
0
 
acslaterAuthor Commented:
ok this is what I have now ... The first part is what I have from the page i am sending from, ie the drop down table:

//connection ....


ResultSet rs = statement.executeQuery("SELECT UserName FROM Member");
String name = null;
ArrayList list =  new ArrayList();
  while ( rs.next() ) {
name=rs.getString("UserName");
list.add(name);
}
%>
                          <%
{
    connection.close();
}

%>
                    </p>
                    <p>
Send SMS to:&nbsp;&nbsp;&nbsp
 <select>
  <%  
     if(list != null)
     {
       for(int i =0; i < list.size(); i++)
       {
           String value = (String) list.get(i);
  %>
      <option value="<%=value%>"><%=value%></option>
 
  <%}
  }
  else
  {%>
    <option value=dummy>None</option>
  <%}%>
  </select>
                    <p>
                    <form name="frm1" id="frm1" method="post" action="sent.jsp" onSubmit="return validateForm(frm1)">
                   
                      <input type="submit" name="Submit3" value="Send">                    
                      <p></form>&nbsp;                    </p>

//This is the page that it is going to / requesting called sent.jsp


 <%
out.print("Administrator logged in: " + session.getValue("UserName")+ "<br>");
%>
                    </p>
                    <p>                
  <%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=&password=");    
statement = connection.createStatement();

 String name  = "'" + request.getParameter("name") + "'";


ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("name"));

String user = "//user";
String  password = "//password";
String  api_id = "//api-id";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi from ...";
String  to = "Phone";
if(rs.next())
{
user = "user";
password = "password";
api_id = "api_id";
baseurl ="http://api.clickatell.com";
text = "Hi from ...";
to =rs.getString("Phone");
}
%>
<html>
<body onload=document.forms[0].submit();>
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>">
</form>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  


//Now I actually have it requesting the page and displaying it without any errors
But it is not sending the message. Is it because Phone is not set properly, or the wrong "name" / "username" is selected or anything else you could come up with?

0
 
KuldeepchaturvediCommented:
any of your above mentioned stuff can throw the SMS sending away... best way is to do a right click on the page and see if the parameters are the way you want them to be in the form url...
second way of testing it wd be taking the url from the form ( one that shows up in the view source of your HTML).
paste it in a browser and see if it sends the SMS for you.....
0
 
acslaterAuthor Commented:
ok ive tried that, whats being posted is the following

http://api.clickatell.com/http/sendmsg?user=xxx&password=xxx&api_id=xxx&to=Phone&text=Hi from ...

and the result is ...
ERR: 105, Invalid Destination Address

So i'm guessing its not being pulled properly from the database? Would I need to specify in the select statement "Phone" aswell ...
0
 
KuldeepchaturvediCommented:
ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("name"));
Most probably this statement is not fetching any row form the  database..
here I am assuming that you have got a field named"phone" in your database, because that what we are trying to get from this select query.. Also if the username is of type string ( which most probably it is).. then you will have to write it in following manner..
ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+request.getParameter("name")+"'");
i.e. put single quotes around the value... then only it will match.. ( I hate SQL for that)....
0
 
acslaterAuthor Commented:
Ok i tried changing that around but no luck, its still not passing through the Phone no.
Yes there is a field called Phone in the table Member. Would this be because I need to request it after the Select statement ...
"+request.getParameter("Phone")+" ??
0
 
KuldeepchaturvediCommented:
your phone parameter is coming from request or its coming from database??
if its coming from database then
if(rs.next())
{
user = "user";
password = "password";
api_id = "api_id";
baseurl ="http://api.clickatell.com";
text = "Hi from ...";
to =rs.getString("Phone");
}

this piece shd be assigning it to the to field..
if its coming from the request then we need to go a request.getParameter("Phone");
post your current jsp and also tell me what all fields are being provided to this jsp so that we can look in to it...
0
 
acslaterAuthor Commented:
Ok that what I had. Theres no errors when i do it, but message is not sent. If I replace
>> to =rs.getString("Phone");

with

>>to =rs.getString("3538xxxxxxxx");

The message is still not sent, but no errors. But if I view the souce of that page and post the method in the URL it WILL send the message to that number. The Phone number is coming from the database, when a User is selected from the drop down menu, so rs.getString("Phone"); should be used? The following is the code I have.


<%
out.print("Administrator logged in: " + session.getValue("UserName")+ "<br>");
%>
                    </p>
                    <p>                
  <%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=combcdte_admin&password=*sonyt630*");    
statement = connection.createStatement();

 String name  = "'" + request.getParameter("name") + "'";


ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("name"));

/*
ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+request.getParameter("UserName")+"'");
*/

String user = "xxx";
String  password = "xxx";
String  api_id = "xxx";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi from ...";
String  to = "Phone";
if(rs.next())
{
user = "user";
password = "password";
api_id = "api_id";
baseurl ="http://api.clickatell.com";
text = "Hi from ...";
to =rs.getString("Phone");
}
%>
<html>
<body onload=document.forms[0].submit();>
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>">
</form>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  
0
 
KuldeepchaturvediCommented:
okay lets do these two things in your jsp..

<%
out.print("Administrator logged in: " + session.getValue("UserName")+ "<br>");
%>
                    </p>
                    <p>                
  <%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=combcdte_admin&password=*sonyt630*");    
statement = connection.createStatement();

 String name  = "'" + request.getParameter("name") + "'";
System.out.println("user is : -->"+name); // to check if we are getting the user name correctly

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("name"));

/*
ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+request.getParameter("UserName")+"'");
*/

String user = "xxx";
String  password = "xxx";
String  api_id = "xxx";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi from ...";
String  to = "Phone"; //if this does not work then change the phone number to some hardcoded number for testing
if(rs.next())
{
user = "user";
password = "password";
api_id = "api_id";
baseurl ="http://api.clickatell.com";
text = "Hi from ...";
to =rs.getString("Phone");
}
%>
<html>
<body>
<frame  src="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>"></frame>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  

try this and let me know what it prints at the console for user name... and if its the correct user name as per the database...
0
 
RaftorCommented:
I think your problem is simply the phone number you are sending to. It has to be in the format +35387....   Change this and then try sending it through the url to test it. When that works concentrate on how you send it from the jsp page.
0
 
acslaterAuthor Commented:
Raftor
>>The message is still not sent, but no errors. But if I view the souce of that page and post the method in the URL it WILL send the message to that number
0
 
acslaterAuthor Commented:
I've tried your above help.
I added in the necessary.
When i submit, the result from

>>out.println("user is : -->"+name); // to check if we are getting the user name correctly

is user is : -->'null'
0
 
KuldeepchaturvediCommented:
yup! that means its not getting the user name that you are hoping that it will get!..
since the user name is not correct, your query is not returning anything and hence we do not have the phone number...

how you are passing the user name to this page?
post the code of that page where user selects some user name and you post the data to this jsp... then I shd be able to find out the problem
0
 
acslaterAuthor Commented:
I'm using
+request.getParameter("name"));

//Where the user selects a user from the db ....


ResultSet rs = statement.executeQuery("SELECT UserName FROM Member");
String name = null;
ArrayList list =  new ArrayList();
  while ( rs.next() ) {
name=rs.getString("UserName");
list.add(name);
}
%>
                          <%
{
    connection.close();
}

%>
                    </p>
                    <p>
Send SMS to:&nbsp;&nbsp;&nbsp
 <select>
  <%  
     if(list != null)
     {
       for(int i =0; i < list.size(); i++)
       {
           String value = (String) list.get(i);
  %>
      <option value="<%=value%>"><%=value%></option>
 
  <%}
  }
  else
  {%>
    <option value=dummy>None</option>
  <%}%>
  </select>
                    <p>
                    <form name="frm1" id="frm1" method="post" action="sent.jsp" onSubmit="return validateForm(frm1)">
                   
                      <input type="submit" name="Submit3" value="Send">                    
                      <p></form>&nbsp;                    </p>


// The jsp ...


 String name  = "'" + request.getParameter("name") + "'";
out.println("user is : -->"+name); // to check if we are getting the user name correctly

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+request.getParameter("name"));

/*
ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+request.getParameter("name")+"'");
*/

String user = "xxx";
String  password = "xxx";
String  api_id = "xxx";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi from ...";
String  to = "353xxxxxxxxx";
if(rs.next())
{
user = "user";
password = "password";
api_id = "api_id";
baseurl ="http://api.clickatell.com";
text = "Hi from ...";
to =rs.getString("Phone");
}
%>
<html>
<body onload=document.forms[0].submit();>
<form method="post" action="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>">
</form>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  


//If you find this problem and dosent work, i'll try
out.println("phone is : -->"+phone); // for the same reason as above
0
 
KuldeepchaturvediCommented:
you form is written wrongly...
the select box shd have been inside the form..!!


<p>
                    <form name="frm1" id="frm1" method="post" action="sent.jsp" onSubmit="return validateForm(frm1)">
             

<select name="name">
  <%  
     if(list != null)
     {
       for(int i =0; i < list.size(); i++)
       {
           String value = (String) list.get(i);
  %>
      <option value="<%=value%>"><%=value%></option>
 
  <%}
  }
  else
  {%>
    <option value=dummy>None</option>
  <%}%>
  </select>
                      <input type="submit" name="Submit3" value="Send">                    
                      <p></form>&nbsp;                    </p>


and then in sent.jsp  ( which I am assuming is the same one that we were working on so far).. you do a
request.getParameter("name");
0
 
acslaterAuthor Commented:
Ok i've changed the above.
In the sent.jsp page, does it matter where I put the
>>request.getParameter("name");

??

Does the following look correct or which part do I leave out?

String name  = "'" + request.getParameter("name") + "'";
out.println("user is : -->"+name); // to check if we are getting the user name correctly

// or

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+request.getParameter("name")+"'");

Which ever way i put it, it will either bring up a blank page or an error
0
 
KuldeepchaturvediCommented:
your sent.jsp should look like following...

<%
out.print("Administrator logged in: " + session.getValue("UserName")+ "<br>");
%>
                    </p>
                    <p>                
  <%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=combcdte_admin&password=*sonyt630*");    
statement = connection.createStatement();

String name  = "'" + request.getParameter("name") + "'";
System.out.println("user is : -->"+name); // to check if we are getting the user name correctly

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+name);

String user = "xxx";
String  password = "xxx";
String  api_id = "xxx";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi from ...";
String  to = "Phone"; //if this does not work then change the phone number to some hardcoded number for testing
if(rs.next())
{
System.out.println("found phone");
to =rs.getString("Phone");
}
%>
<html>
<body>
<frame  src="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>"></frame>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  
here I am assuming that you will replace the user and password values to actual values instead of 'xxx'..... see what it prints on the console....
it should be the user name that you selected...
and if it finds the phone number in the data base it will print "found" as well on the console....
0
 
acslaterAuthor Commented:
Yep :) ... gettin there

>>it should be the user name that you selected...
and if it finds the phone number in the data base it will print "found" as well on the console....

It prints out the above.
If I leave
>>String  to = "Phone";
or hard code it
>>String  to = "35386xxxxxxx";

It finds the correct phone no, checked in the view source. Still no message sent though
0
 
KuldeepchaturvediCommented:
and you say that if you cut & paste the url it send the message right???

Hmm.....
alright lets do this..
<html>
<body>
<frame  src="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>"></frame>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>

change this piece to

<html>
<head>
</head>
<script>
window.locaton="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>";
</script>
 </html>

if your posting to the browser is making it to send the SMS.. this code shd be doing the same thing....
0
 
acslaterAuthor Commented:
>> and you say that if you cut & paste the url it send the message right???

exactly!

I duno whats up with it.

Tried the above and its te same as the previous attempts.
If i post it in the URL manually, it sends the message, and then displays an ID number (for that message) on the page
0
 
KuldeepchaturvediCommented:
I hate to fix this problem like this but lest give it a try

<html>
<head>
</head>
<script>
function callit()
{

window.open("http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>");
}
</script>
<body onload="callit();">
It shd pop up a window with the ID number.
</body>
 </html>

try this
0
 
acslaterAuthor Commented:
Legend ; )
Good stuff that worked.
Brings up the error in explorer with the pop up blocker, but works fine in firefox.
If you happen to find out a way around it to post it properly in the same browser, it would be great, but this is fine thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 17
  • 15
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now