Posts Tagged ‘件的’

用标准件的方式来组装网页DIV布局-WEB标准网站设计心得

星期三, 06月 4th, 2008

有这样一个想法,不知道可行么

例子:

布局中de左栏,它de属性有:{居左,宽度,背景色,字体等等}

如果把每个属性都做成一个标准件,然后这样组装起来使用

class="float width height background font padding….",通过多个classde标准件de引用来完成页面布局样式

先按需要定义好标准件如:

float标准件

.l{float:left}

.r{float:right}

.cl{clear:left}

width标准件

.w200{width:200px}

.w300{width:300px}

background标准件

.red{background:red}

.black{background:#000}

.white{background:#fff}

根据需要引用

class="l w200 red"[居左,宽度为200,背景红色]

class="r w200 white" [居右,宽度为200,背景白色]

我现在自己写相关代码,最多就2个class来定义一个布局样式,感觉很方便

ASP.Net防止刷新自动触发事件的解决方案

星期二, 06月 3rd, 2008

  使用asp.net,在刷新页面de时候会自动触发服务器端de事件.举个简单de例子,如:一个注册页面,我填写完注册信息之后,如果按F5刷新之后,会自动触发到Button事件上,这样就造成了又注册了一次de麻烦.

  我先前de解决方案:用关键字查询,如有相同,则提示已有此用户.

  但是这种方案不能在没有表识de情况下使用,他会重新提交.鉴于此,我寻找了一种新de解决方案,很庆幸,在朋友de提点下,迸发了这样de解决方案,肯定有更好de解决方案,不吝赐教.

  解决思路:刷新时,捕捉KeyPress,让他触发其他无用de事件.

  1、捕捉F5事件deJavaScript

window.document.onkeydown = KeyStroke;
function KeyStroke()
{
var key = event.keyCode;
event.srcElement.releaseCapture();
if(key == 116)
{
document.getElementById(”Button1″).click();
event.keyCode=0;
event.returnValue=false;
}
}

  2、aspx页面放置一个Button

<asp:Button id=”Button1″ style=”Z-INDEX: 102; LEFT: 344px; POSITION: absolute; TOP: 408px; WIDTH: 0px;” runat=”server”
Text=”Button”></asp:Button>

  3、Button事件

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write( “You have pressed the key F5″);
}

  这个“舍车保帅”de方案,能解决刷新自动触发事件de解决方案这个小问题,如果谁有更好de方案,希望告诉我一声,不胜感激!

第一次用.net2.0 LOGIN登陆控件的困惑和解决方法

星期二, 06月 3rd, 2008

1、我没有真正de服务器,我只是租用了.net2.0 SQLserver空间,SQL数据库名是固定de.
2、空间提供商不可能给我设定数据源或给您aspnetdb数据库权限.
3、我没有服务器de \Windows\Microsoft.Net\Framework\v2.x\Config 权限.

已知上面三点,如果直接把本地测试好de项目传到服务器肯定会出错(因为他默认是调用\Windows\Microsoft.Net\Framework\v2.x\Config ),我认为好de解决方法是把aspnetdb数据库内容全部导入自己de远程SQL数据库后,再定义项目deweb.config数据库连接字符串.
web.config
<?xml version=”1.0″?>

<!–
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序de设置.可以使用 Visual Studio 中de
“网站”->“Asp.Net 配置”选项.
设置和注释de完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
–>
<configuration xmlns=”http://schemas.microsoft.com/.NetConfiguration/v2.0“>
<connectionStrings>

<!–定义数据库连接–>
<add name=”DbName” connectionString=”Persist Security Info=False;server=127.0.0.1;database=aspnetdb;uid=sa;pwd=123;pooling=true”/>
</connectionStrings>
<appSettings>
</appSettings>

<system.web>

<!–
connectionStringName 数据库连接.这个要在web.config设置
enablePasswordRetrieval 获得一个值,指示当前成员资格提供程序是否配置为允许用户检索其密码.
enablePasswordReset 获得一个值,指示当前成员资格提供程序是否配置为允许用户重置其密码.
requiresQuestionAndAnswer 获取一个值,该值指示默认成员资格提供程序是否要求用户在进行密码重置和检索时回答密码提示问题.
applicationName 获取或设置应用程序de名称.
requiresUniqueEmail 指示用户在创建用户时是否必须提供唯一de电子邮件地址值.
passwordFormat 指示在成员资格数据存储区中存储密码de格式.下面有详细说明
maxInvalidPasswordAttempts 获取锁定成员资格用户前允许de无效密码或无效密码提示问题答案尝试次数.
minRequiredPasswordLength 获取密码所要求de最小长度.
minRequiredNonalphanumericCharacters 获取有效密码中必须包含de最少特殊字符数.
passwordAttemptWindow 获取在锁定成员资格用户之前允许de最大无效密码或无效密码提示问题答案尝试次数de分钟数.

对PasswordFormat de详细说明
属性指示存储密码de格式.密码可以采用 Clear、Encrypted 和 Hashed 密码格式存储.Clear 密码以明文形式存储,这可以提高存储和检索密码de性能,但安全性较差,当数据源安全性受到威胁时此类密码很容易被读取.Encrypted 密码在存储时进行了加密,可以在比较或检索密码时进行解密.此类密码在存储和检索时需要进行额外de处理,但比较安全,在数据源de安全性受到威胁时不容易被获取.Hashed 密码在存储到数据库时使用单向哈希算法和随机生成de salt 值进行哈希处理.在验证某一密码时,将用数据库中de salt 值对该密码进行哈希计算以进行验证.无法检索哈希密码.
–>


<roleManager enabled=”true” />
<membership>
<providers>
<remove name=”AspNetSqlMembershipProvider”/>
<add name=”AspNetSqlMembershipProvider”
type=” System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
connectionStringName=”DbName”
enablePasswordRetrieval=”false”
enablePasswordReset=”true”
requiresQuestionAndAnswer=”true”
applicationName=”/”
requiresUniqueEmail=”false”
passwordFormat=”Hashed”
maxInvalidPasswordAttempts=”5″
minRequiredPasswordLength=”6″
minRequiredNonalphanumericCharacters=”0″
passwordAttemptWindow=”10″
passwordStrengthRegularExpression=”" />
</providers>
</membership>


<!–
设置 compilation debug=”true” 可将调试符号插入
已编译de页面中.但由于这会
影响性能,因此只应在开发过程中设置
此值.

Visual Basic 选项:
设置 strict=”true” 将禁止所有会导致
数据丢失de类型转换.
设置 explicit=”true” 将强制声明所有变量.
–>
<compilation debug=”true” strict=”false” explicit=”true”/>
<pages>
<namespaces>
<clear/>
<add namespace=”System”/>
<add namespace=”System.Collections”/>
<add namespace=”System.Collections.Specialized”/>
<add namespace=”System.Configuration”/>
<add namespace=”System.Text”/>
<add namespace=”System.Text.RegularExpressions”/>
<add namespace=”System.Web”/>
<add namespace=”System.Web.Caching”/>
<add namespace=”System.Web.SessionState”/>
<add namespace=”System.Web.Security”/>
<add namespace=”System.Web.Profile”/>
<add namespace=”System.Web.UI”/>
<add namespace=”System.Web.UI.WebControls”/>
<add namespace=”System.Web.UI.WebControls.WebParts”/>
<add namespace=”System.Web.UI.HtmlControls”/>
</namespaces>
</pages>
<!–
通过 <authentication> 节可以配置 ASP.NET 使用de
安全身份验证模式,
以标识传入de用户.
–>
<authentication mode=”Forms” />
<!–
如果在执行请求de过程中出现未处理de错误,
则通过 <customErrors> 节可以配置相应de处理步骤.具体说来,
开发人员通过该节可以配置
要显示de html 错误页
以代替错误堆栈跟踪.

<customErrors mode=”RemoteOnly” defaultRedirect=”GenericErrorPage.htm”>
<error statusCode=”403″ redirect=”NoAccess.htm” />
<error statusCode=”404″ redirect=”FileNotFound.htm” />
</customErrors>
–>

</system.web>
</configuration>

注:membership节点de那个注释是转载de,忘了地址了.

Java操作文本文件的方法

星期一, 06月 2nd, 2008

最初java是不支持对文本文件de处理de,为了弥补这个缺憾而引入了Reader和Writer两个类,这两个类都是抽象类,Writer中write(char[] ch,int off,int length),flush()和close()方法为抽象方法,Reader中read(char[] ch,int off,int length)和close()方法是抽象方法.子类应该分别实现他们.
  当我读写文本文件de时候,采用Reader是非常方便de,比如FileReader,InputStreamReader和BufferedReader.其中最重要de类是InputStreamReader,它是字节转换为字符de桥梁.您可以在构造器重指定编码de方式,如果不指定de话将采用底层操作系统de默认编码方式,例如GBK等.当使用FileReader读取文件de时候.
  FileReader fr = new FileReader(”ming.txt”);
  int ch = 0;
  while((ch = fr.read())!=-1 )
  {
  System.out.print((char)ch);
  }
  其中read()方法返回de是读取得下个字符.当然您也可以使用read(char[] ch,int off,int length)这和处理二进制文件de时候类似,不多说了.如果使用InputStreamReader来读取文件de时候
  while((ch = isr.read())!=-1)
  {
  System.out.print((char)ch);
  }
  这和FileReader并没有什么区别,事实上在FileReader中de方法都是从InputStreamReader中继承过来de.read()方法是比较好费时间de,如果为了提高效率我可以使用BufferedReader对Reader进行包装,这样可以提高读取得速度,我可以一行一行de读取文本,使用readLine()方法.
  BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(”ming.txt”)));
  String data = null;
  while((data = br.readLine())!=null)
  {
  System.out.println(data);
  }
  当您明白了如何用Reader来读取文本文件de时候那么用Writer写文件同样非常简单.有一点需要注意,当您写文件de时候,为了提高效率,写入de数据会先放入缓冲区,然后写入文件.因此有时候您需要主动调用flush()方法.与上面对应de写文件de方法为:
  FileWriter fw = new FileWriter(”hello.txt”);
  String s = “hello world”;
  fw.write(s,0,s.length());
  fw.flush();
  OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(”hello2.txt”));
  osw.write(s,0,s.length());
  osw.flush();
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(”hello3.txt”)),true);
  pw.println(s);
  不要忘记用完后关闭流!下面是个小例子,帮助新手理解.其实有de时候javadeIO系统是需要我多记记de,不然哪天就生疏了.
  hello world i like java language
  import java.io.*;
  public class TestFile2
  {
  public static void main(String[] args) throws IOException
  {
  FileReader fr = new FileReader(”ming.txt”);
  char[] buffer = new char[1024];
  int ch = 0;
  while((ch = fr.read())!=-1 )
  {
   System.out.print((char)ch);
  }
  InputStreamReader isr = new InputStreamReader(new FileInputStream(”ming.txt”));
  while((ch = isr.read())!=-1)
  {
   System.out.print((char)ch);
  }
  BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(”ming.txt”)));
  String data = null;
  while((data = br.readLine())!=null)
  {
   System.out.println(data);
  }
  FileWriter fw = new FileWriter(”hello.txt”);
  String s = “hello world”;
  fw.write(s,0,s.length());
  fw.flush();
  OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(”hello2.txt”));
  osw.write(s,0,s.length());
  osw.flush();
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(”hello3.txt”)),true);
  pw.println(s);
  fr.close();
  isr.close();
  br.close();
  fw.close();
  osw.close();
  pw.close();
  }
  }

下载文件的点击数回填

星期一, 06月 2nd, 2008

需要名称为bookdemysql数据库表
表中含有下列字段:
id 下载de文件de唯一标识
downnum 点击数
first.php
<?while($myrow = @mysql_fetch_array($result))
{
?>
<TR>
<TD>
<?if(empty($myrow["downnum"])) echo "0"; else echo $myrow["downnum"]; ?>
</TD>
<TD>
<a href="ddload.php?purl=downfileurl&dnnum=<?echo $myrow['downnum'] ?>&id=<?echo $myrow['id']?>">click here download </a>
</TD>
</TR>
<?};?>
ddload.php
<?
include("data.inc.php");
if($incerror)
{
echo $incerror;
exit;
}
if(empty($dnnum)) $dnnum = 1;
else $dnnum ;
$sql = "update book set downnum =’$dnnum’ where id =$id";
mysql_query($sql);
mysql_close($connect);
header("location:$purl");
?>

星期一, 06月 2nd, 2008

<?php
//对Javascript和select部件de结合运用
//在写程序de过程,我想实现在select对象选中选项后,
//不需要提交按钮,而直接触发动作,且在动作发生后
//de页面中要保持所选择de选项.经过形容,终于通过
//使用Javascript及select对象deonchange属性及
//value值而实现了这种功能.
//相关代码如下(文件名为"test.php"):

switch ($mon){
case ”: echo ‘请选择您de星座:’;break;
case ‘1′:echo ‘您de星座是水瓶座’;break;
case ‘2′:echo ‘您de星座是双鱼座’;break;
case ‘3′:echo ‘您de星座是白羊座’;break;
case ‘4′:echo ‘您de星座是金牛座’;break;
case ‘5′:echo ‘您de星座是双子座’;break;
case ‘6′:echo ‘您de星座是巨蟹座’;break;
case ‘7′:echo ‘您de星座是狮子座’;break;
case ‘8′:echo ‘您de星座是处女座’;break;
case ‘9′:echo ‘您de星座是天平座’;break;
case ‘10′:echo ‘您de星座是天蝎座’;break;
case ‘11′:echo ‘您de星座是射手座’;break;
case ‘12′:echo ‘您de星座是魔蝎座’;break;
default:break;
}
?>
<form name="form1">
<select name="month_select"
onChange="javascript:location.href=
this.options[this.selectedIndex].value">
<option>–请选择您de星座–</option>
<option value="test.php?mon=1"
<?php if($mon=="1") echo " selected"; ?>>水瓶座</option>
<option value="test.php?mon=2"
<?php if($mon=="2") echo " selected"; ?>>双鱼座</option>
<option value="test.php?mon=3"
<?php if($mon=="3") echo " selected"; ?>>白羊座</option>
<option value="test.php?mon=4"
<?php if($mon=="4") echo " selected"; ?>>金牛座</option>
<option value="test.php?mon=5"
<?php if($mon=="5") echo " selected"; ?>>双子座</option>
<option value="test.php?mon=6"
<?php if($mon=="6") echo " selected"; ?>>巨蟹座</option>
<option value="test.php?mon=7"
<?php if($mon=="7") echo " selected"; ?>>狮子座</option>
<option value="test.php?mon=8"
<?php if($mon=="8") echo " selected"; ?>>处女座</option>
<option value="test.php?mon=9"
<?php if($mon=="9") echo " selected"; ?>>天平座</option>
<option value="test.php?mon=10"
<?php if($mon=="10") echo " selected"; ?>>天蝎座</option>
<option value="test.php?mon=11"
<?php if($mon=="11") echo " selected"; ?>>射手座</option>
<option value="test.php?mon=12"
<?php if($mon=="12") echo " selected"; ?>>魔蝎座</option>
</select>
</form>

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】

树型结构列出指定目录里所有文件的PHP类

星期一, 06月 2nd, 2008

<?
//以树型结构列出指定目录里de所有文件,如果您想知道自己某个目录里有哪些子目录和文件,可以调用这个类来查看,很方便de.
# 演示de例子:
$t = new TreeClimber( "asp" ); //新建物件,设置需要列出de目录:在此为asp目录
echo arrayValuesToString( $t->getFileList( $t->getPath() ), "<BR>\n" );
function arrayValuesToString( $ar, $nl="", $dolast=true ) {//调用函数
$str = "";
reset( $ar );
$size = sizeof( $ar );
$i = 1;
while( list( $k, $v ) = each( $ar ) ) {
if ( $dolast == false ) {
if ( $i < $size ) {
$str .= $ar[$k].$nl;
}
else {
$str .= $ar[$k];
}
}
else {
$str .= $ar[$k].$nl;
}
$i ;
}
return $str;
}
?>
<?
//以下为类文件
class TreeClimber {
var $path;
var $fileList = array();
function TreeClimber( $path = "." ) {
$this->path = $path;
}
# 存取路径
function getPath() { return $this->path; }
function setPath( $v ) { $this->path = $v; }
// 返回指定目录里de文件列表,如果没有指定目录,将使用当前目录
//如果不能打开目录(可能没权限或目录不存在,将返回为空
//以递归方式进行
function getFileList( $dirname=null, $returnDirs=false, $reset=true ) {
if ( $dirname == null ) { $dirname = $this->path; }
# else { $this->setPath( $dirname ); }
# dout( "Recursing into $dirname…" );
if ( $reset ) {
$this->fileList = array();
}
$dir = opendir( $dirname );
if ( ! $dir ) {
print( "<B><FONT COLOR=#FF0000>注意: TreeClimber.getFileList( $dirname ): 不能打开 $dirname!</FONT></B>" );
return null;
}
while( $file = readdir( $dir ) ) {
if ( ereg( "^\.$", $file ) || ereg( "^\.\.$", $file ) ) continue;
if ( is_dir( $dirname."/".$file ) ) {
$this->getFileList( $dirname."/".$file, $returnDirs, false );
if ( $returnDirs ) { $this->fileList[] = $dirname."/".$file;}
}
else { $this->fileList[] = $dirname."/".$file; }
}
sort( $this->fileList );
return $this->fileList;
}
} //至此类结束
?>

给多个地址发邮件的类

星期一, 06月 2nd, 2008

<?php
////////////////////////////////////////////////////////////
// EmailClass 0.5
// class for sending mail
//
// Paul Schreiber
// php@paulschreiber.com
// http://paulschreiber.com/
//
// parameters
// ———-
// - subject, message, senderName, senderEmail and toList are required
// - ccList, bccList and replyTo are optional
// - toList, ccList and bccList can be strings or arrays of strings
// (those strings should be valid email addresses
//
// example
// ——-
// $m = new email ( "hello there", // subject
// "how are you?", // message body
// "paul", // sender’s name
// "foo@foobar.com", // sender’s email
// array("paul@foobar.com", "foo@bar.com"), // To: recipients
// "paul@whereever.com" // Cc: recipient
// );
//
// print "mail sent, result was" . $m->send();
//
//
//
if ( ! defined( ‘MAIL_CLASS_DEFINED’ ) ) {
define(’MAIL_CLASS_DEFINED’, 1 );
class email {
// the constructor!
function email ( $subject, $message, $senderName, $senderEmail, $toList, $ccList=0, $bccList=0, $replyTo=0) {
$this->sender = $senderName . " <$senderEmail>";
$this->replyTo = $replyTo;
$this->subject = $subject;
$this->message = $message;
// set the To: recipient(s)
if ( is_array($toList) ) {
$this->to = join( $toList, "," );
} else {
$this->to = $toList;
}
// set the Cc: recipient(s)
if ( is_array($ccList) && sizeof($ccList) ) {
$this->cc = join( $ccList, "," );
} elseif ( $ccList ) {
$this->cc = $ccList;
}
// set the Bcc: recipient(s)
if ( is_array($bccList) && sizeof($bccList) ) {
$this->bcc = join( $bccList, "," );
} elseif ( $bccList ) {
$this->bcc = $bccList;
}
}
// send the message; this is actually just a wrapper for
// PHP’s mail() function; heck, it’s PHP’s mail function done right :-)
// you could override this method to:
// (a) use sendmail directly
// (b) do SMTP with sockets
function send () {
// create the headers needed by PHP’s mail() function
// sender
$this->headers = "From: " . $this->sender . "\n";
// reply-to address
if ( $this->replyTo ) {
$this->headers .= "Reply-To: " . $this->replyTo . "\n";
}
// Cc: recipient(s)
if ( $this->cc ) {
$this->headers .= "Cc: " . $this->cc . "\n";
}
// Bcc: recipient(s)
if ( $this->bcc ) {
$this->headers .= "Bcc: " . $this->bcc . "\n";
}
return mail ( $this->to, $this->subject, $this->message, $this->headers );
}
}

}
?>

以文本方式上传二进制文件的PHP程序

星期一, 06月 2nd, 2008

现在有de站点上传文件de时候会自动在文件前面加入Content-type: image/gif等头标,导致二进制文件被破坏.因此,我编写了以文本方式上传二进制文件dePHP程序.
  一共两个文件:index.php,action.php.将要上传de文件de文件名改为test,与这两个文件放在一起,运行index.php,选读取,将读取de所有数据Copy,在远端服务器上面也运行这个程序,Paste到输入框中,选保存.二进制文件就被上传了.
index.php
———————————————————
<html>
<head>
<title>以文本方式上传二进制文件dePHP程序</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<table width="760" border="0" cellspacing="0" cellpadding="0" height="25">
<tr>
<td>
<div align="center"><b>图片上传</b></div>
</td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form name="form" method="post" action="action.php" target="_blank">
<div align="center">
<textarea name="pic" cols="80" rows="15"></textarea>
<br>
<input type="radio" name="view" value="0" checked>
保存  
<input type="radio" name="view" value="1">
试看  
<input type="radio" name="view" value="2">
读取<br>
<input type="submit" name="OK" value=" 确 定 ">
 
<input type="reset" name="RESET" value=" 取 消 ">
</div>
</form>
</td>
</tr>
</table>
</body>
</html>
———————————————————
action.php
———————————————————
<?

PHP 增加了对 .ZIP 文件的读取功能

星期一, 06月 2nd, 2008

This module uses the functions of the ZZIPlib library by Guido Draheim to transparently read ZIP compressed archives and the files inside them.
这个模块使用 ZZIPlib 库(Guido Draheim)来读取 ZIP 压缩文档和里面de文件
Please note that ZZIPlib only provides a subset of functions provided in a full implementation of the ZIP compression algorithm and can only read ZIP file archives. A normal ZIP utility is needed to create the ZIP file archives read by this library.
请注意:这个库只是ZIP所有扩展功能de一个子集,只能读取 ZIP 文档里面de内容.一个普通de ZIP 环境需要能创建 ZIP 文档
Zip support in PHP is not enabled by default. You will need to use the –with-zip configuration option when compiling PHP to enable zip support. This module requires ZZIPlib version >= 0.10.6.
PHP 没有默认支持 ZIP,您需要使用 –with-zip 配置编译您de PHP.这个模块需要 ZZPIlib 版本>=0.10.6
Note: Zip support before PHP 4.0.7 is experimental. This section reflects the Zip extension as it exists in PHP 4.0.7 and later.
注意:zip在 4.0.7之前是测试de.这一章写de是 php4.0.7 和以后版本de东西
Example Usage
This example opens a ZIP file archive, reads each file in the archive and prints out its contents. The test2.php archive used in this example is one of the test archives in the ZZIPlib source distribution.
Example 1. Zip Usage Example
<?php
$zip = zip_open("/tmp/test2.zip");
if ($zip) {
while ($zip_entry = zip_read($zip)) {
echo "Name: " . zip_entry_name($zip_entry) . "\n";
echo "Actual Filesize: " . zip_entry_filesize($zip_entry) . "\n";
echo "Compressed Size: " . zip_entry_compressedsize($zip_entry) . "\n";
echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "\n";
if (zip_entry_open($zip, $zip_entry, "r")) {
echo "File Contents:\n";
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
echo "$buf\n";
zip_entry_close($zip_entry);
}
echo "\n";
}
zip_close($zip);
}
?>