hi
i m a total servlet n00b...so i dont quite understand what is happening here.
i got a javascript from the net ( http://scripts.hashemian.com/js/countdown.js )
i saved it onto my hard-drive. as countdown.js...
i then wrote a servlet program whose code is shown below:
[/b](case1)[/b]
the java file(Execute.java) and javascript(countdown.js) are in the same folder...sitting beside each other.Code:import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Execute extends HttpServlet { public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.println("<html>"); out.println("<head>"); out.println("</head>"); out.println("<body>"); out.println("<script language=\"JavaScript\">"); out.println("TargetDate = \"1/1/2009 12:00 AM\""); out.println("BackColor = \"palegreen\""); out.println("ForeColor = \"navy\""); out.println("CountActive = true"); out.println("CountStepper = -1"); out.println("LeadingZero = true"); out.println("DisplayFormat = \"%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds. for new years\""); out.println("FinishMessage = \"It is finally here!\""); out.println("</script>"); out.println("<script language=\"JavaScript\" src=\"countdown.js\"></script>"); out.println("<p>it works!!</p>"); out.println("</body></html>"); out.close(); } }
i then compile the java file and i then create a .war file...
the war file, i deploy on the apache-tomcat server, using the tomcat manager. but when i run the servlet, the javascript does not run.
(case2)
when i set "src=" as ,
and again deploy it on tomcat server, the script gets fetched from the http:// website and runs.Code:out.println("<script language=\"JavaScript\" src=\"http://scripts.hashemian.com/js/countdown.js\"></script>");
(case3)
when i create a html file as shown below
the script that i have saved(and i call) on the harddisk runs and everything works out.Code:<html> <body> <script language="JavaScript"> TargetDate = "1/1/2009 12:00 AM"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds. for new years"; FinishMessage = "It is finally here!"; </script> <script language="JavaScript" src="countdown.js"></script> <p> it works!! </p> </body> </html>
so thats my story.
In case(1) the js file saved on the hard-disk is called, but it does not get executed
In case(2) the same js file is retrived from the internet and the script gets executed
In case(3) instead of using a servlet i create a static html page and call the javascript saved on the hdd and it works
the servlets "web.xml" files code is as shown below
so why is it that case(1) does not work out but case(2) and case(3) work???Code:<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <servlet-name>Execute</servlet-name> <servlet-class>Execute</servlet-class> </servlet> <servlet-mapping> <servlet-name>Execute</servlet-name> <url-pattern>/Execute</url-pattern> </servlet-mapping> </web-app>
please help out.
if you dont understand what i m trying to say...i have uploaded the war files...they are only 5KB...it would be really nice...if you people could take a look at them and understand my problem first-hand.
1.war file that has javascript pointing to http://scripts.hashemian.com/js/countdown.js/ - http://www.savefile.com/files/1950654
2.war file that has javascript pointing to the local hard-disk - http://www.savefile.com/files/1950656




Reply With Quote