如何在服务器端机器上创建.txt文件。 [英] how to create .txt file on the server side machine.

查看:95
本文介绍了如何在服务器端机器上创建.txt文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





问题:我正在研究HTML应用程序,HTML页面包含用户名,密码和登录



按钮。当我输入用户名和密码并单击登录按钮时,我想创建一个文本



文件并将用户名写入服务器端机器上的文本文件中。





我已经像上面的问题一样实现了html页面,但主要的问题是当我调用html



从服务器通过Internet Explorer中的URL到本地计算机的页面。当我输入



用户名和密码时,不会在服务器端创建.txt文件。



我实施的Page是这样的,



 <  < span class =code-leadattribute> html  >  
< title > Mutiara SMART < < span class =code-leadattribute> / title >
< SCRIPT language = JavaScript >

函数WriteFile()
{
var username = document.getElementById('txtUserName')。value;
var Scr = new ActiveXObject(Scripting.FileSystemObject);
var CTF = Scr.CreateTextFile(C:\\DataBuffer,true,true);
CTF.WriteLine(username);
CTF.Close();
}

< / SCRIPT >
< head >

< link href = admin.css rel = 样式表 类型 = text / css >

< / head >
< body >

< center >
< img src = smart.jpg >
< width = 350 border = 0 align = center cellpadding = < span class =code-keyword> 5
cellspacing = 1 bgcolor = 灰色 class = entryTable >
< tr < span class =code-attribute> id = entryTableHeader >
< td > :: Login :: < / td >
< ; / tr >
< tr >
< td class = contentArea >

< table width = < span class =code-keyword> 100% border = 0 cellpadding = 2 cellspacing = 1 < span class =code-attribute> class = text >
< tr align = center >
< span class =code-keyword>< td colspan = 3 > & nbsp; < / td >
< / tr >
< tr class = text >
< span class =code-keyword>< td width = 100 align = right > 用户名< / td >
< td width = 10 align = center > < / td >
< td > < 输入 名称 = txtUserName 类型 = text class = box id = txtUserName value = size = 30 maxlength = < span class =code-keyword> 100 > < / td >
< < span class =code-leadattribute> / tr >
< tr >
< td w宽度 = 100 align = right > 密码< / td >
< td width = 10 align = center > < / td >
< td > < 输入 name = txtPassword type = password class = id = txtPassword value = size = 30 > < / td >
< / tr >
< tr >
< td colspan = 2 > & nbsp; < / td >
< td >
& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; < a onClick = javascript:CreateFile(); > 登录< ; / a > & nbsp;& nbsp;& nbsp;& ;& nbsp;& nbsp; < / td >
< / tr >
< / table >

< < span class =code-leadattribute> / center >

< ; / body >

< / html >







任何人都可以知道如何在服务器端创建.txt文件。



先谢谢你。

解决方案

基本的是Javascript在CLIENT SIDE上执行。如果您在Javascript中使用ActiveX对象来编写文本文件,那么它(如果确实有效)将文件写入客户端计算机而不是服务器上。



这是服务器端脚本编写的地方。创建一个带有服务器端编码的动态网页,将文件写入服务器上的磁盘。



您可以浏览ASP.NET,PHP和其他Web技术

您可以从客户端调用Ajax请求,并从该服务器端执行方法。该方法将负责创建文本文件。您只需发送用户名或其他内容作为参数。您可以查看链接。介意它ActiveX对象使用它不推荐practive,只有IE可以支持它。


Hi,

ISSUE: I am working on HTML application, an HTML page contains a username, password and Login

button. When i enter the username and password and click Login button, i want to create a text

file and write the username in to the text file on the server side machine.


I have implemented the html page like above issue, but the main problem is when i call the html

page from the server in to the local machine through URL in Internet Explorer. When i enter the

Username and password the .txt file is not created at the server side.

The Page i implemented is like this,

<html>
<title>Mutiara SMART</title>
<SCRIPT language="JavaScript">

function WriteFile()
{
   var username = document.getElementById('txtUserName').value;
   var Scr = new ActiveXObject("Scripting.FileSystemObject");
   var CTF = Scr.CreateTextFile("C:\\DataBuffer", true, true);
   CTF.WriteLine(username);
   CTF.Close();
}

</SCRIPT>
<head>

<link href="admin.css" rel="stylesheet" type="text/css">

</head>
<body>

<center>
<img src = "smart.jpg">
 <table width="350" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="gray" class="entryTable">
        <tr id="entryTableHeader">
         <td>:: Login ::</td>
        </tr>
        <tr>
         <td class="contentArea">

    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="text">
           <tr align="center">
            <td colspan="3">&nbsp;</td>
           </tr>
           <tr class="text">
            <td width="100" align="right">Username </td>
            <td width="10" align="center">:</td>
            <td><input name="txtUserName" type="text" class="box" id="txtUserName" value="" size="30" maxlength="100"></td>
           </tr>
           <tr>
            <td width="100" align="right">Password </td>
            <td width="10" align="center">:</td>
            <td><input name="txtPassword" type="password" class="box" id="txtPassword" value="" size="30"></td>
           </tr>
           <tr>
            <td colspan="2">&nbsp;</td>
            <td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onClick="javascript: CreateFile();">Login</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
           </tr>
          </table>

</center>

</body>

</html>




can anyone give an idea on how to create .txt file on server side.

Thank you in Advance.

解决方案

The basic thing is that the Javascript executes on CLIENT SIDE. If you are using ActiveX objects in Javascript to write the text file , then it will ( if it really works) write the file to client machine and not on the server.

This is where the server side scripting comes into picture. Create a dynamic webpage with server side coding where it writes a file to the disk on server.

You can explore ASP.NET, PHP and other web technologies


You can call Ajax request from client side and from that server side method will execute. That method will responsible to create text file. You just send username or other things as argument. You can check the Link. Mind it ActiveX object use it not recommended practive, only IE can support it.


这篇关于如何在服务器端机器上创建.txt文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆