LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2004, 04:53 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
How to run a server-side Javascript in Apache


I am running an Apache web server under Linux.
The Java script below suppose to write a file
named servertype.conf to a web server under
the directory /var/apache/.

The Java script responded properly but it did not create a file.
This Java script is embedded within a Python script, and the
Pyhton script does run.
There is an error. Error 'File is undefined'

The code var mysummary = new File("/var/apache/servertype.conf")
is a server-side script.
How do I get this server-side script to work in Apache ?
This code is also shown on line number 10 below.

===========================

Alternatively, I could use a Server Side Include (SSI) feature to
write to a file in a web server with the statement as showned
on line number 9 below.

The code AddHandler server-parsed .conf
would then be added to the file /etc/httpd/conf/httpd.conf

So far I could not get either of the two methods to work.
I am running Apache version 1.3.26
===========================
Code:
1) <SCRIPT LANGUAGE="Javascript">
2) <!--

//Javascript added by Linh on 7-13-2004 for switching between
//master iserver and secondary iserver

3) function select_button (form)
4)  {
5)   if (form.defms[1].checked)
6)     if (confirm ("You are changing from a master iserver 
                            to a secondary iserver. Is this what you want ? 
                            To complete this process, you must 
                            1) Enter Iserver IP address. 
                            2) Enter the Iserver Registration Password. 
                            3) and finally click the button 
                                 'Apply Changes to System'") )
7)       {
8)         alert ("Clicked Yes");

9)         <!--#exec echo "ServerType=Secondary" > /var/apache/servertype.conf -->

10)    var mysummary = new File("/var/apache/servertype.conf");
         mysummary.open("w");
         mysummary.write('ServerType=Secondary');
         mysummary.flush();
         mysummary.close();

       }
     else
      {
        form.defms[1].checked = false
        form.defms[0].checked = true
        alert ("Clicked No");
      }
 }
//-->
</SCRIPT>

 <input type=radio name="defms" value="ms" onClick="select_button (this.form)" %s></td>
<input type=radio name="defms" value="ss" onClick="select_button (this.form)" %s></td>

Last edited by Linh; 07-13-2004 at 05:02 PM.
 
Old 07-14-2004, 03:30 PM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Ok, I'm not 100% sure of how you're using Javascript, but if you want the user to see that confirm dialog, it must be being run client side in a browser. Consequentally that code you've pasted must be in the html sent to the browser, and the SSI code will have already been parsed by the server before sending the html to the user.

I think your problem is that the JS in this case is executed client side, after the page html is generated and sent. Maybe you need to be passing the dialog result to another page, and/or using a server side language like php to process the form's result (maybe just perl/a cgi script). I've never had to code a site with dynamic pages such as these, so I could be completely wrong, but this is just my suggestion.

Last edited by Proud; 07-14-2004 at 03:32 PM.
 
Old 07-15-2004, 09:36 AM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Thank you Proud for your help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What does it take to create a client side scripting language like JavaScript? tuxfood Linux - General 1 10-04-2005 11:49 AM
How to run the apache server Sharmi Linux - Software 4 03-06-2005 04:19 PM
Javascript/XML client side coding on Linux mkrathi Programming 0 10-04-2004 08:13 AM
can you run an apache server alongside a postfix server mikew101 Linux - Software 5 07-10-2003 07:32 AM
Apache server and MySQL server won't run at startup! dday007 Linux - General 2 02-07-2003 02:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration