How to automate task in jsp?

I want to create an sms messaging website using jsp. The sms i believe would be ez, i would just have to use sockets in a bean. However there is a specific functionality i want to implement where my website would send a dummy sms message every 5 minutes to the sms server just to test what speed that server is accepting messages at. This way i can display the server speed to users when the come to my site. My problem is i am not sure how to implement this functionality in jsp. It is a process that needs to happen like a new thread. It should happen whether or not people are visiting the website and it needs to happed every 5 minutes. I am wondering if this functionality could only be setup by my webserver or is there some way in jsp i could use a bean to do this.
Any assistance would be greatly appreciated

could the same thing be done with a jsp page instead of a servlet?The load on startup part, I'm not sure about. If you only wanted to wait til the first person hits a page, or just have a page that must be hit first on startup of the server to get the thread going, you could do that. But that requires direct user interaction to start things off....
As for examples....
In web.xml, you define a servlet and servlet mapping.
<servlet>
     <servlet-name>smsinit</servlet-name>
     <servlet-class>com.pckg.SMSInitServlet</servlet-class>
     <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/sms-config.xml</param-value>
     </init-param>
     <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
     <servlet-name>smsinit</servlet-name>
     <url-pattern>sms.init</url-pattern>
</servlet-mapping>So that means that if the URL contains "sms.init", the smsinit servlet will be invoked. You probably don't need worry about that, if all you want is something that will load when the server starts. For that, that's what "load-on-startup" is for. The number value has to do with defining load order for multiple servlets. If left out, the servlet isn't initialized til the first time it's called via a URL. Otherwise, any number will do (for all practical purposes). The init-param config is useful if you need to define a file or some parameter that you can use on init to get some other information.
As for the servlet itself
package com.pckg;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SMSInitServlet extends HttpServlet {
     private ServletContext application = null;
     public void init(ServletConfig config) throws ServletException {
          super.init(config);
          application = config.getServletContext();
          String config = application.getInitParameter("config");
          File configFile = new File(application.getRealPath(config));
          // read the file or whatever....
          // start your thread class running and maybe put it in application
          // or pass the thread the application object which it could store
          // information in, or just have the thread use static methods/fields
          // or a singleton instance or something like that. 
          // the advantage to using the application scope is it limits it to being
          // accessed to JSP pages or other servlets within the web application only
     public void doGet(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
          doPost(request, response);
     public void doPost(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
          // do something here...  or nothing, if you want.
}

Similar Messages

  • Automate tasks

    How to automate tasks in indesign ?

    No. Obi-wan's QuicKeys suggestion would work for simple tasks on OSX. The scripting engine is comprehensive—there's not much you can't do with either JavaScript or AppleScript. Unfortunately there's a steep learning curve for complex scripting.

  • How to automate a redundant task on PC to "Include Prefix when Numbering Pages"

    I work in book publishing and we're generating indices using the book feature. The big problem is that for the print version we need the folios styled a certain way "without a prefix" but to create our index in the book feature, the prefix needs to be turned on.
    Is there any way to do any kind of drag and drop so I don't have to open every chapter of the file to turn the prefix on? Though it doesn't take long, it's repetitive and has to be done every time we update our books. (The "Section Prefix" information is alreay inserted, it's just a matter of toggling it on or off depending on what doing in the InD file.)
    I do not write scripts. It seems like a simple task but would take me months to figure out. If you can send me to someone who can figure out how to automate this task, I would greatly appreciate your help.
    Macgrunt was able to help me but then I realized I was on a PC. Is this something that can be done in Javascript?

    Here's a version that batch-processes the selected folder with InDesign documents as you asked in PM.
    Main();
    function Main() {
        var inddFile, doc,
        inddFolder = Folder.selectDialog("Choose a folder with InDesign documents.");
        if (inddFolder == null) exit();
        var inddFiles = inddFolder.getFiles("*.indd");
        if (inddFiles.length == 0) ErrorExit("Found no InDesign documents in the selected folder.", true);
        for (var i = 0; i < inddFiles.length; i++) {
            inddFile = inddFiles[i];
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
            doc = app.open(inddFile);
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;   
            sections = doc.sections;
            for (var j = 0; j < sections.length; j++) {
                sections[j].includeSectionPrefix = true;
            doc.close(SaveOptions.YES);
    function ErrorExit(error, icon) {
        alert(error, scriptName, icon);
        exit();
    You can also use this script to run a script or a set of scripts on a bunch of files. (Warning! It's not totally tested)

  • How to automate the data load process using data load file & task Scheduler

    Hi,
    I am doing Automated Process to load the data in Hyperion Planning application with the help of data_Load.bat file & Task Scheduler.
    I have created Data_Load.bat file but rest of the process i am unable complete.
    So could you help me , how to automate the data load process using Data_load.bat file & task Scheduler or what are the rest of the file is require to achieve this.
    Thanks

    To follow up on your question are you using the maxl scripts for the dataload?
    If so I have seen and issue within the batch (ex: load_data.bat) that if you do not have the full maxl script path with a batch when running it through event task scheduler the task will work but the log and/ or error file will not be created. Meaning the batch claims it ran from the task scheduler although it didn't do what you needed it to.
    If you are using maxl use this as the batch
    "essmsh C:\data\DataLoad.mxl" Or you can also use the full path for the maxl either way works. The only reason I would think that the maxl may then not work is if you do not have the batch updated to call on all the maxl PATH changes or if you need to update your environment variables to correct the essmsh command to work in a command prompt.

  • How to Automatically generate .XSL file of XML file ???

    Hello Everyone,
    I have UI which provide the facility to create own format by using drag and drop utility. I have also xml file which contains the data. Now task is how to automatically generate the .xsl file of the dynamically designed format for the data stored in xml form.
    If you have any idea about the solution of the above problem.
    I will thankful for any help regarding this…
    Thanks
    B. Kumar

    XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents. .xsl is the extension of the XSL file.Thank you, I am aware of all that.
    When we design any format by using drag & drop utility, System has to generate the .xsl file (extensible stylesheet for the xml document).Why? To accomplish what?
    And then .xsl file is used to display the data which is stored in xml document on the webpage with designed format.So you need to define the mapping between XML and HTML? and you're hoping to do that automatically?
    That's a job for a user interface designer. Not a tool.
    In brief we need to write a parson
    Parser
    which will take any designed format and generate the .xsl file for that design, to display the data which is stored in XML document.Doesn't make sense. It would make more sense if you started from a schema. Starting from an actual XML document, i.e. an instance of the schema, no, not even slightly.

  • How to automate Import/export Essbase data 11.1.2

    Hi,
    After migration from Dev to Test environment using LCM (EPMA Planning, Shared services) I have questions:
    1) How to automate export from source and import in Destination?
    2) If we have enabled MSAD in shared services, What should be standard practice to sync provisioning in both environment?
    Regards
    Kumar

    Hi John,
    I see only Native directory
    Application Group>Foundation>shared services> - Native directory
    - Task flows
    Application Group>Foundation>shared services> - Native directory>assigned Roles> foundation>shared services
    I feel MSAD should be here but not sure as it is just new environment and we enabled MSAD.
    Please suggest where can i check Import/export in LCM 11.1.2?
    Regards
    Kumar
    Edited by: Kumar 1 on Oct 20, 2011 3:22 AM

  • How to automate 2 actions in System Preferences?

    I'd like to automate clicking to hide the dock and hide the clock in the menu bar.  I tried to record this using Automater.  System Preferences needs to be open and on he home view for this to work.
    Also, automater sometimes hangs and there is no way to kill it or gain control of your Mac when this happens.  Any ideas how to automate these task?

    Buy another Mac

  • Scheduling a task on jsp

    Hi,
    I need help, i'm trying to schedule a task on jsp, but i have no idea how i can do it...
    I did this class:
    package util;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.Calendar;
    import java.util.Date;
    public class Horas{
    Timer timer;
    Date time_fin;
    public void Programa(int periodo, Date inicio) {
      timer = new Timer();
      timer.schedule(new RemindTask(), inicio, periodo*1000);
    class RemindTask extends TimerTask {
      public void run() {
       Calendar fecha_actual = Calendar.getInstance()
       Date ahora = fecha_actual.getTime();
       if(time_fin.before(ahora))
        timer.cancel();
       else
        //  here goes the task
    public void setHorafinal(Date hora){
      time_fin=hora;
    }And from my jsp i call these methods using an useBean...
    <jsp:useBean id="sampleHorasid" scope="request" class="util.Horas" />
    <%
    sampleHorasid.setHorafinal(time_fin);
    sampleHorasid.Programa(10,time_ini);
    %>That works ok, but i want to write anything on the browser every time that invokes run()...
    It works if i put something like System.out.println(...); inside public void run(), but i want to write on the browser, not on console..
    Any idea about how can i do it?? :S
    Thanks!!!

    That works ok, but i want to write anything on the browser every time that invokes run()...
    It works if i put something like System.out.println(...); inside public void run(), but i want to write on the browser, not on console..
    Any idea about how can i do it?? :S
    An applet.
    The normal http request and response lifecyle does not allow you to push data arbitarily to the client browser. The only way you can write back to the browser is when it has sent a request to the server and you have a handle to the output response stream.
    cheers,
    ram.

  • Sending automatic mail using JSP or Servlet

    hello,
    i was just wondering if anyone out there knows how can automatically send emails to client from my application after receiving thier email address. the email address is received from a form and i want my application to automatically send a structured email to the client as soon as they click the send button. i am using JSP and tomcat as my server. any help will be appreciated

    You must create a class that sends the mail:
    A code example would be like this:
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import java.util.*;
    public class MailSender {
         public void postMail(String smtpsrv, String recipients[], String subject,
                   String message, String from) throws MessagingException {
              boolean debug = false;
              //Set the host smtp address
              Properties props = new Properties();
              props.put("mail.smtp.host", smtpsrv);
              // create some properties and get the default Session
              Session session = Session.getDefaultInstance(props, null);
              session.setDebug(debug);
              // create a message
              Message msg = new MimeMessage(session);
              // set the from and to address
              InternetAddress addressFrom = new InternetAddress(from);
              msg.setFrom(addressFrom);
              InternetAddress[] addressTo = new InternetAddress[recipients.length];
              for (int i = 0; i < recipients.length; i++) {
                   addressTo[i] = new InternetAddress(recipients);
              msg.setRecipients(Message.RecipientType.TO, addressTo);
              // Setting the Subject and Content Type
              msg.setSubject(subject);
              msg.setContent(message, "text/html;charset=utf-8");
              Transport.send(msg);
    You 'll find out that its easy to understand the code.
    I advise you not to change this code.
    I also include an example of how to right the JSP code:
    <%
    MailSender MS = new MailSender();
    try {
         MS.postMail(server, recipient,"Your E-mail Title", "BODY content", from);
         } catch (MessagingException e1) {
                        e1.printStackTrace();
    %>
    This JSP code follows the pattern of the above class
    Hope to help you
    Cheers!!!

  • Automate Task in Notification

    Good Day Everyone
    Has anyone ever automated the task line on service notification under the repair tab to create a task line when the material was received into stock for repair (IW52 transaction)?  This is customer stock coming into the plant for repair through an inbound delivery.   On ECC 6.0
    Please share some experiences and how it was accomplished.
    Edited by: Kimberly Blair on Jun 23, 2010 3:57 PM

    Hi,
    Your thread is more related to Task related in CS Module, Pls explore the following links, you  should get a solution.
    Automatic Task determination link:
    http://help.sap.com/saphelp_46c/helpdata/en/26/1afd0b7d5911d38aef0000e8284931/content.htm
    http://www.onestopsap.com/sap-study-material/upload/pm-cs-plant-maintenance-cu.pdf
    Also for one of your query use Partner determinatiom procedure for notifiction type,
    Regards
    DSR
    Edited by: D.Srinivasa Rao on Nov 18, 2011 7:58 AM

  • OB52 Posting Period Close:  Does anyone know how to automate the close?

    Does anyone know how to automate the FI Period Close (trans code OB52)?  Currently, the business users go into the screen and open and close any periods manually.  For the MM period close, we are able to do so because we found the program to use in the batch job.  For some reason, the FI side shows the program SAPL0F00 but this is only a view and will not allow a batch job to be created.  Does anyone know of the actual program used for the FI period close?

    Use program RFPERIOD_OPEN.  It may help.  For further details you may check the following thread.
    RFPERIOD_OPEN

  • How can i access the jsp file in a asp file

    Hi every one..
    we have two projects one is developed in ASP and one is developed in JSP both are running in two different locations.
    now i want to include a jsp file from one project to ASP file in the other project.
    please tell me how can i insert the JSP file in ASP application.
    thanx in advance.

    Wouldn't that be an ASP question for an ASP forum?

  • How to print report in jsp page?

    excuse me,i am new to jsp
    may i know how to pritn report in jsp page or html?
    tq

    here is a hacked up example.. i ripped out a lot, so it may not compile, but you get the idea... the full version is really long and not much new info.. just all awt/display stuff...
    package rowe;
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.sql.*;
    import utility.*;
    import java.awt.print.*;
    public class rowePrint extends JFrame implements ActionListener, Printable{
         String printType = "";
         static JButton j = new JButton("Print");
         FontMetrics fm;
         String jID, promotion, product, jComments;
         public void getInfo(int jid) {
              ResultSet rs;
              try {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection conn = DriverManager.getConnection("jdbc:odbc:rowe");
                   Statement stmt = conn.createStatement();
                   rs = stmt.executeQuery("select j.id as jID, j.comments, p.title as pTitle, p.product, p.packagingCartonCost, p.foldingQuarterCostPerM, p.foldingQuarterCostPerM, j.customizationOption as setupFee, p.perMcost, p.qtyCarton, d.name as dName, d.contact as dContact, d.email as dEmail, d.address as dAddress, d.city as dCity, d.state as dState, d.zip as dZip, d.phone as dPhone, d.fax as dFax, r.name as rName, j.totalQty, j.orderIn, j.estFreight, j.miscCost, j.coverSelection, j.imprintSelection from jobs j, promotions p, dealers d, reps r where j.promotion = p.id and j.dealer = d.id and j.rep = r.id and j.id = " + jid);
                   rs.next();
                   jID = rs.getString("jID");
                   jComments = rs.getString("comments");
                   promotion = rs.getString("pTitle");
                   product = rs.getString("product");
              } catch (Exception e) {
                   System.out.println("getinfo: " + e);
       public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JButton) {  
                   wookie();
         public void wookie() {
              PrinterJob printJob = PrinterJob.getPrinterJob();
              Paper paper = new Paper();
              PageFormat page = new PageFormat();
              paper.setImageableArea(0, 0, 600, 780);            
              page.setPaper(paper);
              printJob.setPrintable(this, page);
              try{
                   //printJob.pageDialog(page);
              //     if (printJob.printDialog()) {
                        printJob.print();
              } catch (Exception e) {
                   System.out.println("wookie1" + e);
         public static void main(String[] args) {
              rowePrint at = new rowePrint("Invoice");
              at.getInfo((new Integer(args[0])).intValue());
              at.drawShapes();
         //     at.wookie();
         public void drawShapes() {
              setBounds(0, 0, 670, 550);
              addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
              j.setBounds(10, 10, 10, 10);
              j.addActionListener(this);
              getContentPane().setLayout(null);
              getContentPane().add(l);
              getContentPane().add(j);
              show();
         public rowePrint(String s){
              printType = s;
         public void paint(Graphics g) {
              g.setFont(new Font("Serif", Font.BOLD, 18));
              g.drawString(promotion, 20, 30);
              g.setFont(new Font("SansSerif", Font.PLAIN, 4));
              g.drawString("" + new java.util.Date(), 20, 37);
              g.setFont(new Font("Serif", Font.BOLD, 21));
              g.drawString("Rowe Furniture", 440, 35);
              g.fillRect(440, 40, 145, 25);
              g.setColor(Color.white);
              fm = g.getFontMetrics(new Font("Serif", Font.BOLD, 21));
              g.drawString(printType, 512 - (fm.stringWidth(printType) / 2), 60);
        public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
            if (pi >= 1) {
                return Printable.NO_SUCH_PAGE;
              paint(g);
            return Printable.PAGE_EXISTS;
    }

  • How to attach Task List in Notification

    Hi all
    How to attach Task List in Notification?
    Thanks.

    List item is forms is generally used when you have pre-defined set of values. you can define them property of list item.
    It seems you have dynamic list of values to be displayed on your form, instead go for a text item with a LOV. You can define your logic to get list of values in record group.
    Thanks
    Rishi

  • How to automatically detect server ip address

    does any one know how to automatically detect an ip address of a server from the client with a socket based connection ?
    instead of prompting the client to connect to the server ip address which is trouble some.

    You must start with some initial information and a known environment.
    There are several possibilities after that.
    - The server has a 'name'. This is not an ip address but a name like "yahoo.com". When you connect using that, even if the IP changes, the correct IP will be returned. (At least ignoring an annoying bug in some VMs)
    - A specific IP address
    - Use a methodoly to 'request' a server address. One version of this is to use a UDP broadcast another version uses a service manager (which itself must be found.)

Maybe you are looking for

  • On MAC Flex NativeWindow changes window position after opening

    I have opened a nativewindow in center.This works fine on windows But on MAC it intially opens at center for few milliseconds and it then moves to top-Left position. var aboutDialog:AboutDialog = new AboutDialog(); aboutDialog.type = CSXSWindowType.T

  • Do I still have to double-click a clip to see it's date and time?

    iMovie 4 and earler, when you clicked on a clip in the timeline, the time and date would show up right there in the grey area. Then in iMovie 5, that is gone. Now I have to double-click every single clip to see the same info. This has made me very an

  • Need mac address to get ATV on wireless

    Mac address filtering is on - I need to find the mac address on ATV so that I can use this thing! Any ideas how to do that?

  • Making those window pane bars go away

    I'm sure that is the dumbest question to date, 'cause I'm sure it's obvious to everyone else, but I haven't been able to find the answer anywhere. Here's the deal: I got a psd file with several layers in it from another person. I have successfully wo

  • 10.3.4 on intel mac?

    Is it possible to put server 10.3.4 on my intel mac? ibook g3? imac g4? I have tried to install apple server on my external hard drive, which I recently reformatted and according to disk utility should be able to start up from. But when I try to inst