troubleshooting Question

Need change this to a class file

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


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="java.io.*" %>
<%@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");
      tz.setDefault(tz);

      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 = "";
                        out.println(compact.item(i).getFirstChild().getNodeValue()+"<BR>");
                        out.println(brands.item(i).getFirstChild().getNodeValue()+"<BR>");
                        out.println(expiry.item(i).getFirstChild().getNodeValue()+"<BR>");
                        out.println(ratings.item(i).getFirstChild().getNodeValue()+"<BR><BR>");
                        
                        StringTokenizer str = new StringTokenizer(brands.item(i).getFirstChild().getNodeValue(), ",");
                        while(str.hasMoreTokens()) {
                              brandlist = brandlist + "'" + str.nextToken().trim()+"',";                        
                        }
                        brandlist = brandlist.substring(0,brandlist.length()-1);
                        
                        out.println("result="+brandlist);
      
                        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.");
                        }
                        
                        try
                        {
                              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 (rs.next()) {
                                    /*sendemail2("ryancys@hotmail.com","ryancys@lycos.com","ryan","subj", compact.item(i).getFirstChild().getNodeValue().trim());
                                    emailsent=emailsent+1;*/
                                    sendsms2(rs.getString("mobile"), compact.item(i).getFirstChild().getNodeValue().trim());
                                    smssent=smssent+1;
                              }
                              out.println("End sending sms..<BR>SMS sent: "+smssent);
                        }
                        catch(SQLException e)
                        {
                              //conn.setAutoCommit(true);
                              conn.rollback();
                              e.printStackTrace();
                        }
                        finally
                        {
                              //conn.setAutoCommit(true);
                              conn.commit();
                              
                              if (stm != null)
                              {
                                    stm.close();
                              }
                              
                              if (rs != null)
                              {
                                    rs.close();
                              }
                        }
                        
                        quote.setHost("http://localhost:8080/scbpme/xmlcontent/"+xmlfile);
                        quote.setMethod("get");
            
                        s=quote.action();
            
                        quote.setTemplate("%1");
                        v=quote.parse(s);
            
                        if (v.size()>1)
                          s=v.elementAt(1).toString();
                        else
                          s="";
                        out.println(application.getRealPath("/xmlcontent/"+xmlfile)+"<br>");
                        out.println("v.size()="+v.size()+"<br>");
                        out.println("s="+s+"<br>");
                        if (!s.equals("")) {
                              FileWriter fw = new FileWriter(application.getRealPath("/xmlsuccess/"+xmlfile), true);
                              fw.write(s);
                              fw.flush();
                              fw.close();
                              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!");
            
      }
      
%>

Thanks
ASKER CERTIFIED SOLUTION
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