?
Solved

I NEED TO HAVE A TIMER IN MY WEB SITE!!

Posted on 2003-02-26
40
Medium Priority
?
323 Views
Last Modified: 2010-08-05
I do not know how timers work in Java, what I want to do is the following:

I want to have a timer, that starts once the webpage is loaded, and after 2 minutes I want to re-direct the user to another website and update some values in my Database. Can someone please help me with this, I have a day and half left to finish my project.

Thank you very much in advance...

Perrosucio
0
Comment
Question by:perrosucio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 16
  • 7
  • +1
40 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8029506
You could try:

<meta
http-equiv="refresh" content="5;URL=http://www.xxx.com">
0
 

Author Comment

by:perrosucio
ID: 8029574
I tryed that but it executes the action of the database when it loads the website and not after the time set, that its why I am trying to use java instead of the html meta...

Thank you once again CEHJ...

Perrosucio
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8031484
pls write the following line between <head> </head>

<meta http-equiv="refresh" content="60;URL=ANYURL">

where:

60 = no of seconds (1 minute)
ANYURL = its the url where u want to redirect, for example http://www.yahoo.com

 
0
Independent Software Vendors: 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!

 
LVL 3

Expert Comment

by:NetWize
ID: 8032074
import java.applet.*;
import java.net.*;

public class Timer extends Applet {
//Hm. Maybe init() works as well.
 public void start() {
  try {
  Thread.sleep(1000 * secs);
  getAppletContext().showDocument(new URL("yourlink"), "top");
  } catch(Exception e) {
  }
 }
}
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8032081
But If the user has java disabled (nothing happens) or uses Sun Plugin (takes 2 Minutes to load...) this wont be it.

Have you tried JavaScript?

<script>
  function go() {
    top.location.href = 'yoururl';
  }
  var sec = 60;
  window.setTimeout("go()", 1000 * sec);
</script>
0
 

Author Comment

by:perrosucio
ID: 8033090
I want to have an action attached to the refresh or the timer, do not know which one will do the job for me,

 umangjoshi: can I attached a piece of code written in java to tha meta statement? The thing is that my pages are a combination of html, javascript and java, therefore I need to use a timer implemented in Java to make it efficient. As I said in my previous comment I have already tryed the meta statement and it does the refresh to the desired URL but if I attach an action to it then it does the action when loading the page and not after 2 minutes.

  One thing I am sure about all the users and is that they all will use Internet Explorer, therefore no problem with Sun pluggins an so on.

  Thank you very much for your time and help...

  Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033140
Slow down a bit... What do you mean with "action attached" on the refresh?

Sou you have some code (Java?) you want to execute after the timeout, ok. The Applet will do this, just insert it instead of the "showDocument".
But if you want the code to be executed ON THE SERVER, you need to write a Servlet / JSP and call this as result of the "refresh". You could control this by adding a parameter like

http://yoururl?doAction=true
on refresh.

You could even "call" that servlet/jsp without changing the website the user sees by opening a new Connection from the applet to the server.

Could you please be a bit more specific about what you are trying to do? Especially: Where is the code to be executed on refresh and do you "have" the code already?
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033164
Ah just read your message again carefully...

You need a jsp or a servlet which will do the database-update you were talking about and then send a redirect to the page you want to go to.

Fortunatly, that's easy.

Basically a JSP doing this would look like

<%
// You DB-update here

//You know how to do that?

//If you read the page to redirect to from parameter
response.sendRedirect("http://"+request.getParameter("goto"));
%>

/*
Simple Redirect:
response.sendRedirect("http://www.google.de");
*/
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8033245
umangjoshi, please don't simply repeat other people's answers. This adds nothing to the discussion, especially when the questioner has already rejected the comment you are repeating.
0
 

Author Comment

by:perrosucio
ID: 8033260
Yeah I have some code written in java to execute once the time has expired, for example:
I want to do the following thing:

String Query1="update table set name='myname' where id='myid'";
perfom_query.executeQuery(Query1);
conn.commit();
conn.setAutoCommit(true);

All the display things on the website are done using HTML and the queries to database and other things are done using Java, sorry if I am not good explaining my problem, hope this will make more sense to you...Thanks...

Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033304
As I said: JSP or serlvet would be what you need.

What server are you running that on? If you don't have it I'd recommend tomcat 4.1 for a start.

If you have that up and running copy all your html into ./webapps/ROOT/ and you can serve your page from tomcat.
Then create a file "redir.jsp" and put the <% %> i posted above plus your own DB-Code in it (everything between <% and %> will be treaded as Java-Code)

0
 

Author Comment

by:perrosucio
ID: 8033333
It is running under Sun server, not familar with what you say about JSP or servlet, I am really new in this of Java a web programming, stuck all the time when trying to do something new.

I fyou want I can show you all the code and you can see what I am doing.

Thanks..

Perrosucio
0
 

Author Comment

by:perrosucio
ID: 8033380
It is an internal thing for a company, so I am using the server they gave me...

0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033388
Ok. I suggest you go and get yourself a tomcat running from
http://jakarta.apache.org/tomcat/ Of course you'll need a JDK for that.

Installation is pretty easy.

If you have it listening on Port 8080 that would be a first big step.
After that copy your website (all the html in folders)
into the folder webapps/ROOT/ in your new tomcat and check
if it still works (calling http://localhost:8080/ and seeing your index.html)

When done with that drop a line and we check that timer-thing.
By the way: The tomcat-documentation is pretty good and there are some really easy samples for a beginning.

0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033438
Oh. Too bad. Could you please find out what server that is exactly and if you can install a JSP in there? (By asking that company I'd say ;-)
As it's by Sun (or is it only running on a Sun) there is probably some java in there...
0
 

Author Comment

by:perrosucio
ID: 8033452
One more thing NetWize, my pages are not index.html or so, they are they have the following name: my_page.java and my_page.class (after compiled), do not know if this will give you any extra information...

Thanks...

Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033491
ok. so probably servlets?

can you show me a page from wich you know that it works?

0
 

Author Comment

by:perrosucio
ID: 8033492
I have J2EE in this machine, with the libraries and and their respective cgi's, do I need anything else apart from that?  What do you mean with JSP. Hope this could help...

Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033551
Ah J2EE is great :-)

JSP is a type of java-file wich contains html and java code in a mixed way. It gets compiled on first invocation by the J2EE server.

Benefit of jsp over servlet is that the HTML stays readable (and not out.println() all the time) and that you can easily test it by editing the file itself (wich gets recompiled after change)

JSP-File means a file wich ends on .jsp and contains that type of code...

you have direct access to the servers directories? how do you test what you are developing?

and can you send me a file you know to work?
0
 

Author Comment

by:perrosucio
ID: 8033555
HERE IS AND EXAMPLE OF THE CODE OF ONE PERFECT WORKING PAGE:

import java.sql.*;
import java.util.*;
import java.lang.*;
class ver_cola
{
  public static void main (String args [])
       throws SQLException
  {
        try {
                String num_mensajes="select count(*) lineas from mensajes";
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                Connection conn =
                DriverManager.getConnection (Constantes.baseDeDatos,Constantes.login,Constantes.clave);
                Statement Total_mensajes = conn.createStatement ();
                Statement Contenido_fila = conn.createStatement ();
                String lineas=" ";
               
            
            String pagina=  "  <html>\n"+
                        "  <head>\n"+
                        "  <meta http-equiv='Content-Language' content='en-us'>\n"+
                        "  <meta name='GENERATOR' content='Microsoft FrontPage 5.0'>\n"+
                        "  <meta name='ProgId' content='FrontPage.Editor.Document'>\n"+
                        "  <meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>\n"+
                        "  <title>Colas</title>\n"+
                        "  <script language=\"JavaScript\">\n"+
                        "  <!--\n"+
                        "  function salir() \n"+
                        "  {\n"+
                        "      window.location = \"http://io/spaweb/index_io.html\";\n"+
                        "  }\n"+
                        "  </script>\n"+
                        "  <form>\n"+
                                "   <body>\n"+
                                "   <table border=\"3\" cellspacing=\"1\" width=\"100%\" id=\"AutoNumber1\" bgcolor=\"#FFFF00\" height=\"0\">\n"+
                        "   <tr>\n"+
                        "   <td width=\"7%\"><p align=\"center\"><b>ID</td>\n"+
                        "   <td width=\"15%\"><p align=\"center\"><b>FECHA</td>\n"+
                        "   <td width=\"12%\"><p align=\"center\"><b>DURACION</td>\n"+
                        "   <td width=\"42%\"><p align=\"center\"><b>MENSAJE</td>\n"+
                        "   <td width=\"12%\"><p align=\"center\"><b>ESTADO</td>\n"+
                        "   <td width=\"12%\"><p align=\"center\"><b>CARNET</td>\n"+
                        "   </tr>\n";
                  
            System.out.println(pagina);
                        System.out.println("<option value='0'></option>");

                                ResultSet total_lineas = Total_mensajes.executeQuery (num_mensajes);  
               
                            while (total_lineas.next())  
                            {
                                    lineas = total_lineas.getString("lineas");
                                    System.out.println("<input type='hidden' name=\"aux_lineas\" size='2' value='"+lineas+"'>");
                              }
                        
                        Integer tmp;
                        tmp=Integer.valueOf(lineas);
                        int prueba= tmp.intValue();
                        
                              String fila="select carnet,to_char(fecha,'DD-MM-YY') fecha,duracion,mensaje,estado, mens_id from mensajes order by mens_id";
                              ResultSet res_fila = Contenido_fila.executeQuery (fila);
                              
                              while (res_fila.next())  
                              {
                                        String carnet = res_fila.getString("carnet");
                                        String fecha = res_fila.getString("fecha");
                                        String duracion = res_fila.getString("duracion");
                                        String mensaje = res_fila.getString("mensaje");
                                        String estado = res_fila.getString("estado");
                                        String identificacion = res_fila.getString("mens_id");
                                    System.out.println("<td width=\"7%\"><p align=\"center\">"+identificacion+"</td>");
                                             System.out.println("<td width=\"15%\"><p align=\"center\">"+fecha+"</td>");
                                             System.out.println("<td width=\"12%\"><p align=\"center\">"+duracion+"</td>");
                                             System.out.println("<td width=\"42%\">"+mensaje+"</td>");
                                             System.out.println("<td width=\"12%\"><p align=\"center\">"+estado+"</td>");
                                             System.out.println("<td width=\"12%\"><p align=\"center\">"+carnet+"</td>");
                                             System.out.println("</tr>");
                              
                              }
                        
                              System.out.println("</table>");
                                                            
                        String pagina2=      " </small></p><p align='center'>\n"+
                                    " <input type='button' value='Salir' name='Salir' onClick='salir()'></small></p>\n"+
                                    " <p>&nbsp;</p>\n"+
                                    " <DIV ALIGN='RIGHT'>\n"+
                                    " <H4><HR>\n"+
                                    " Febrero 2003. Gerencia de Procesos Operativos\n"+
                                    " </H4>\n"+
                                    " </DIV>\n"+
                                    " </form>\n"+
                                    " </body>\n  </html>\n";
                            System.out.println(pagina2);
      
             }
      catch (SQLException e)
      {
            System.out.println(e);
      }
            
  }
-----------------------------END--------------------

My apologies if it looks messy but it is very long to edit it here in this small text box, do not worry if you don't understand somethings they are written in spanish, but al least you will see the objective of what i am doing.

NOTE: this is not the only page I have 15 oter classes written like this. But the one above is the shortest one only to picture the style of things performed.

Thanks...

Perrosucio
0
 

Author Comment

by:perrosucio
ID: 8033586
I have my own working space in the server and access aswell, hope this will add more ideas to you because I am running short of them..

Thanks...

Perrosucio
0
 
LVL 3

Accepted Solution

by:
NetWize earned 100 total points
ID: 8033621
Ah :-) Now I understand...

You are using Java-Programms as CGI-Scripts! That's cool, but not the best way to do it... You really learn jsp, it's a lot better...

But back to the question (and could you increase the points on this one)...

1. Use any of the suggestions for reloading the page after 2 Minutes, they all will work.
2. Create a new "Page" (Java Program) where you redirect to after the 2 Minutes.
3. Put your SQL-Code there.
4. Write the following HTML-Code to System-out. That will redirect the user to the page you want to show after the 2 minutes (WHERE TO GO)

<html>
<head>
<meta http-equiv="refresh" content="0;url="WHERE TO GO">
</head>
<body>
<script>
//to make sure it works :-)
location.replace("WHERE TO GO");
</script>
</body>
</html>
0
 

Author Comment

by:perrosucio
ID: 8033622
I run my pages in the intranet of the company I have all the connections to the database and other things, I have my own working URL, so once I compiled my classes I go to the explorer and call the URL and check the functionality of it...

Perrosucio

I have run out of points, but I'll give you the points of another question I posted before because 25 it is not enough to all the time you are spending on this one...

Thanks...

Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033642
One more question (just curious):

How do you call that programm from the web? What is the URL to execute that class?

And another try:

create the file testme.jsp and put some simple Content in there:

<%
  //You are from Spain, right?
  response.sendRedirect("http://www.google.es");
%>
And call that page from your browser:

http://whereever/testme.jsp

Just to check if it WOULD work with jsp...
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033663
Are your other questions solved by now? If yes: You havent accepted any of the answers by now.
0
 

Author Comment

by:perrosucio
ID: 8033699
I know what you mean now, what I am going to do is on the URL call another cgi to perform the database code and on that cgi go to the desired re-direction page!! Thanks you very much for your time and help.

Look for unlocked questions under my "perrosucio" username put a comment on it and I will give you the points in all of them, hope this sounds good to you!!!

Thank you once again...

Perrosucio
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8033808
>>put a comment on it and I will give you the points in all of them

I think not Perrisucio! That's not how things work here. NetWize was not even involved in the other questions.
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033866
Well, CEHJ, that's a point. On the other hand, IF my comments helped perrosucio to set up JSP on his server, this would solve at least the IP-Adress problems he had as well. But I Agree that having those other questions deleted would be the better way on that.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8033892
If you want to reward NetWize that's fine, but please post extra points for him if you want to do so. It may seem like there's no reason why you should not "kill two birds with one stone", tidying up your open questions and giving him points at the same time, but remember; this site is a resource for other people. Simply accepting arbitrary answers is inconsequential and could be very confusing for subsequent visitors.
0
 

Author Comment

by:perrosucio
ID: 8033929
I think the way it works is as follows: I have points and if I feel the person help me more than enough and also solved my problem then I should reward him with more than I thought in the beginning, anyway I do with my points what I consider what is right, do you think you have any authority over my points? Did you offer me any concrete solution to the other questions? If yes let me know.

Anyway 25 point s was not enough, probably the comment he is going to add to those questions is the answer to them? It is up to me right?

Well I have to get back to work to finish my program thanks to NetWize, who put a big effort into solving my problem. Good luck CEHJ and see you soon with more questions...

Perrosucio
0
 

Author Comment

by:perrosucio
ID: 8033966
Well I think the answer to those old question are not really helping so I could give point for trying hard into solving it, and specify that the answer was not the right one, but I am awarding points for efforts. I do not understand your point anyway I thought your ranking in the experts things will reflect a more competitive way and also very good postings when helping others right?

See you soon...

Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033971
Calm down...
I think what CEHJ wanted to say is:

You can have those other questions deleted and get the points back for them if you feel they are not answered.

You can "increase" a Question when accepting the answer (if you have points left)

You can wait a few days (your points "recharge") and ask a new question "Points for NetWize" wich is the usual solution if I observed that right.

Have you tried to call that JSP? :-)
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8033975
Calm down...
I think what CEHJ wanted to say is:

You can have those other questions deleted and get the points back for them if you feel they are not answered.

You can "increase" a Question when accepting the answer (if you have points left)

You can wait a few days (your points "recharge") and ask a new question "Points for NetWize" wich is the usual solution if I observed that right.

Have you tried to call that JSP? :-)
0
 

Author Comment

by:perrosucio
ID: 8033980
There are at most 4 questions, so he is not going to take your position in the ranking table...do not stress about it.

Perrosucio
0
 

Author Comment

by:perrosucio
ID: 8034019
NetWize:

The problem has been solved, what I am doing is calling another program, then I do the database queries and then call from this program the desired URL. Thanks for that idea never thought about it.

---------About the points------------

I will delete those questions and put one the way you said

-------------End----------------------

CEHJ: Sorry if I sound angry, you were right!! As NetWize said I will do what he said and also proceed in the right way.

Thank you very much for your time and help...

Perrosucio
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8034049
You are *completely* missing the point Perrosucio, so it's probably better if i get one of the moderators involved here, although i don't really have the time right now.

I don't give a damn about the points - you can give NetWize as many as you want - that's your affair.

The point is this:

this site is more than just a means of your gettings your questions answered and somebody else winning points. It is a *learning* resource for *others*, and that resource should not be compromised by the arbitrary dispensation of points, because it has nothing to do with the problem that was asked and is therefore could be confusing to latecomers to the question thread.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8034067
That above was posted before your last comment - i hope you *have* got the point now Perrosucio ;-)
0
 

Author Comment

by:perrosucio
ID: 8034097
Did you read my apologies? if not, my apologies for what I said above, can you explain me how can I delete those questions to avoid leaving them in the system?

I know this is a learning resource, sorry for the incident

I think the moderator thing is not required we are grown up persons, so we can solve this by ourselves.

My apologies once again...

Perrosucio
0
 
LVL 3

Expert Comment

by:NetWize
ID: 8034178
mea culpa as well: I greedily asked for more points in the first place :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8035832
>>Did you read my apologies?

Yes - accepted thanks.

The thing to do is to leave a good explanation in each question and then contact CS (http://www.experts-exchange.com/Community_Support/). They will refund them if they think it is appropriate to do so.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question