troubleshooting Question

Need change this to a class file

Avatar of Ryan Chong
Ryan ChongFlag for Singapore asked on
18 Comments1 Solution372 ViewsLast Modified:

Recently, I need to able to send sms via a scheduler on a none-Microsoft platform server.

Currently i'm develop the code to send sms using a JSP file, the quesetion is can i executing the JSP file in a scheduler? or how can i amend the code from a JSP file to a Class file?

Here is the sample JSP to send the sms:

<%@include file="./include/setcache.jsp"%>
<%@include file="./include/sendmail2.jsp"%>
<%@include file="./include/sendsms2.jsp"%>

<%@ page language="java" import="Request" %>
<jsp:useBean id="quote" class="Request" scope="page" />
<%@page import="*" %>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page import="javax.xml.parsers.DocumentBuilderFactory, javax.xml.parsers.DocumentBuilder, org.w3c.dom.*"%>
<%@page import="tht.db.*"%>
<%@page import="java.sql.*"%>
<%@include file="./include/init_destroy.jsp"%>

      boolean ispass = false;
      Statement stm = null;
      ResultSet rs = null;
      int emailsent = 0;
      int smssent = 0;
      String brandlist ="";
      String tmpSQL="";
      boolean readisok = false;
      java.util.Vector v;
      String s = "";
      java.util.Date today;
      TimeZone tz = TimeZone.getTimeZone("CTT");

      today = new java.util.Date();
      SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd");
    String logname = formatter1.format(today);
      String xmlfile = "";
      xmlfile = "vivi_sms_"+logname+".xml";
      File dir = new File(application.getRealPath("/xmlcontent/"+xmlfile));
      File dirSent = new File(application.getRealPath("/xmlsuccess/"+xmlfile));
      if (dir.exists()) {
            //check if the xml is sent already
            if (dirSent.exists()==false) {
                  //Do the integration
                  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                  DocumentBuilder db = dbf.newDocumentBuilder();
                  Document doc = db.parse(application.getRealPath("/xmlcontent/"+xmlfile));
                  NodeList compact = doc.getElementsByTagName("compact");
                  NodeList brands = doc.getElementsByTagName("brands");
                  NodeList expiry = doc.getElementsByTagName("expiry_date");
                  NodeList ratings = doc.getElementsByTagName("ratings");
                  int nSize = 0;
                  nSize = compact.getLength();
                  for (int i=0;i<nSize;i++) {
                        brandlist = "";
                        StringTokenizer str = new StringTokenizer(brands.item(i).getFirstChild().getNodeValue(), ",");
                        while(str.hasMoreTokens()) {
                              brandlist = brandlist + "'" + str.nextToken().trim()+"',";                        
                        brandlist = brandlist.substring(0,brandlist.length()-1);
                        tmpSQL = "Select tblSubscriber.Email, tblSubscriber.Mobile from tblSubscriber, tblmbrViviSubscription "+
                                     "Where tblSubscriber.Email = tblmbrViviSubscription.Email "+
                                     "And tblmbrViviSubscription.Subid in ("+brandlist+") Group By tblSubscriber.Email, tblSubscriber.Mobile";
                        if (conn == null)
                              throw new Exception("DBConnection no enactment.");
                              String eV = "";
                              String mV = "";
                              eV = (String)session.getAttribute("emailid");
                              mV = (String)request.getParameter("txtmobile");
                              stm = conn.createStatement();
                              rs = stm.executeQuery(tmpSQL);
                              out.println("Start sending sms..<Br>");
                              while ( {
                                    /*sendemail2("","","ryan","subj", compact.item(i).getFirstChild().getNodeValue().trim());
                                    sendsms2(rs.getString("mobile"), compact.item(i).getFirstChild().getNodeValue().trim());
                              out.println("End sending sms..<BR>SMS sent: "+smssent);
                        catch(SQLException e)
                              if (stm != null)
                              if (rs != null)
                        if (v.size()>1)
                        if (!s.equals("")) {
                              FileWriter fw = new FileWriter(application.getRealPath("/xmlsuccess/"+xmlfile), true);
                              out.println("XML file saved!");
                        } else {
                              out.println("XML file saved error!");
            } else {
                  out.println("SMS sent already previosly!");
      } else {
            //Give 2 more try in 6 hours interval
            // if still not success then inform Administrator      
            out.println("XML file No Found!");

Mick Barry
Java Developer
Join our community to see this answer!
Unlock 1 Answer and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros