前候台相互调用,背包算法,REQUEST的各种变量。

本文介绍了一种前后端交互的方法,包括从前端调用后端服务和从后端调用前端JavaScript函数的技术细节。同时提供了ASP.NET环境下实现这些交互的具体步骤。
ContractedBlock.gifExpandedBlockStart.gifCode
dateadd(hour,-6,getdate()) 

最近看到好几个帖子都在问后台如何调用前台?前台如何调用后台? 
小弟总结了一下share给大家,有不足之处欢迎补充. 

HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JavaScript get Net Function.aspx.cs" Inherits="JavaScript_get_Net_Function" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>前臺與后臺方法護調總結</title>
    
<%--
        JavaScript異步調用定義在ASP.Net頁面中的方法, 我們需要:
            
1.將該方法聲明為公有(public);
            
2.將該方法聲明為類方法(C#中的static,VB.NET中的Shared),而不是實例方法;
            
3.將該方法添加【WebMethod】屬性
            
4.將頁面中ScriptManager控件的EnablePageMethods屬性設置為true;
            
5.在客戶端使用如下JavaScript語法調用該頁面方法
                PageMethods.[MethodName](param1,param2,,callbackFunction);
            
6.為客戶端異步調用指定回調函數,在回調函數中接受返回值并進一步處理;
            
7.添加 using System.Web.Services;
    
--%>
    
    
<%--
        ASP.Net后臺調用JavaScript function的方法,我們要注意:
            
1.盡量少用Response.Write(<script></script>);這種方法,
                                
for (var k = 0; k <



C# code
using System;
using System.Web.Services;
using System.Web.UI;

public partial class JavaScript_get_Net_Function : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {

    }

    
protected void Button1_Click(object sender, EventArgs e)
    {
        
string param1 = "你好:";
        
string param2 = "takako_mu";
        ScriptManager.RegisterStartupScript(
thisthis.GetType(), "edit""CSharpCallJs('" + param1 + "','" + param2 + "');"true);
    }

    [WebMethod]
    
public static string SayHelloFromPage(string name)
    {
        
return string.Format("Hello {0}!", name);
    }
}


using System.Text.RegularExpressions;

// 正则表达式对象
Regex re = new Regex(@"^AB\d{7}$");

// 是否找到匹配
bool yesorno = re.IsMatch("your string");





最近遇到一算法问题: 
有一个int型数组,数组长度为l(l
>0),数组里成员的值互不相等 
现要从中取n个数(n的值要尽可能小),使其总和大等于指定值m(若无法等于m,则要求尽可能地接近) 

public int[] getNewArray(int[] srcArray ,int m ) 

如:
int[] srcArray={1,2,3}; m=6 返回 {3,3
    
int[] srcArray={2,3};  m=1 返回 {2
    
int[] srcArray={2,3,4}; m=9 返回{2,3,4}或{3,3,3




public class FindMax { 

List results 
= new ArrayList(); 

public void find(int[] fs, int m) { 

if (fs == null || fs.length < 1) { 
return


int[] ft = new int[fs.length]; 
for (int i = 0; i < fs.length; i++) { 
ft[i] 
= -1


int c = 0
int j = 0

int[] cs = new int[fs.length]; 

for (int i = 0; i < ft.length; i++) { 

ft[
0= fs[i]; 

= 1
= 0

while (c < fs.length + 1) { 

//如果满足要求,后面的情况不用处理。 
isValid(ft, c, m); 
// if (isValid(ft, c, m)){ 
// j = fs.length; 
// } 

if ( c == fs.length){ 
c
--


if (j == fs.length) { 
if (c == 1) { 
break

c
--
= cs[c]; 
else { 

ft[c] 
= fs[j]; 
cs[c] 
= j + 1

c
++
if (c == fs.length) { 
= cs[c - 1]; 
else { 
= 0






private boolean isValid(int[] f, int c, int m){ 
boolean valid 
= true;; 

for (int j = 0; j < c; j++) { 
if (f[j] == -1) { 
continue


-= f[j]; 


= Math.abs(m); 
Result r 
= null

for ( int i = results.size() - 1; i >= 0; i--){ 
= (Result)results.get(i); 

if ( m > r.no){ 
valid 
= false
break
else if ( m < r.no){ 
results.remove(r); 
valid 
= true
continue
else if ( m == r.no){ 
if ( r.amount < c){ 
valid 
= false
break
}
else if (r.amount > c){ 
results.remove(r); 
valid 
= true
continue



if (isEqual(f, r.f, c)){ 
valid 
= false
break



if (valid){ 
= new Result(); 

r.amount 
= c; 
r.no 
= m; 

r.f 
= new int[c]; 
for ( int j = 0; j < c; j++){ 
r.f[j] 
= f[j]; 


results.add(r); 

return valid; 


public void output(int[] fingles, int c ) { 
StringBuffer s 
= new StringBuffer(fingles.length); 
for (int j = 0; j < c; j++) { 
if (fingles[j] == -1) { 
continue

if (j != 0) { 
s.append(
","); 

s.append(fingles[j]); 

System.
out.println(s.toString()); 


public boolean isEqual(int[] s, int[] d, int c){ 
int[] temp = new int[c]; 

for ( int j = 0; j < c; j++){ 
temp[j] 
= d[j]; 


//查找是否相等 
boolean equal = false
for ( int j = 0; j < c; j++){ 
equal 
= false
for ( int k = 0; k < temp.length; k++){ 
if(s[j] == temp[k]){ 
temp[k] 
= -1
equal 
= true
break


if(!equal){ 
break



return equal; 

public class Result{ 
int amount; 
int no = 0
int[] f = null



/*
* @param args 
*/ 
public static void main(String[] args) { 
FindMax fm 
= new FindMax(); 

int[] fs = { 2,3,4 }; 
int m = 13

// int[] fs = { 1, 2, 3, 4 }; 
// int m = 15; 

fm.find(fs, m); 

FindMax.Result r 
= null
for ( int i = 0; i < fm.results.size(); i++){ 
= (FindMax.Result)fm.results.get(i); 
fm.output(r.f, r.amount); 


// int[] s = {3,5,5}; 
// int[] d = {5,5 ,3}; 
// 
// System.out.println(fm.isEqual(s, d, 3)); 

}




在多线程中,如果是类公共变量, 变量要设成只读形式,不要有可写,因为有可能会出现内存争有。



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>【强烈推荐】 超漂亮的仿腾讯弹出层效果(兼容主流浏览器)</title>
<style>
body {background: #ffffff;    color: #
444;}
a{    color: #09d;    text
-decoration: none;    border: 0;    background-color: transparent;}
body,div,q,iframe,form,h5{    margin: 
0;    padding: 0;}
img,fieldset { border: none 
0; }
body,td,textarea {    word
-breakbreak-all;    word-wrap: break-word;    line-height:1.5;}
body,input,textarea,select,button {    margin: 
0;    font-size: 12px;    font-family: Tahoma, SimSun, sans-serif;}
div,p,table,th,td {    font
-size:1em;    font-family:inherit;    line-height:inherit;}
h5{ font
-size:12px;}
</style>
<script type="text/javascript" src="http://www.5-studio.com/wp-content/uploads/2009/06/Dialog.js"></script>
<script type="text/javascript">
function $(ele) {
  
if (typeof(ele) == 'string'){
    ele 
= document.getElementById(ele)
    
if(!ele){
          
return null;
    }
  }
  
if(ele){
      Core.attachMethod(ele);
    }
  
return ele;
}
var Core 
= {};
Core.attachMethod 
= function(ele){
    
if(!ele||ele["$A"]){
        
return;
    }
    
if(ele.nodeType==9){
        
return;
    }
    var win;
    
try{
        
if(isGecko){        
            win 
= ele.ownerDocument.defaultView;
        }
else{
            win 
= ele.ownerDocument.parentWindow;
        }
        
for(var prop in $E){
            ele[prop] 
= win.$E[prop];
        }
    }
catch(ex){
        
//alert("Core.attachMethod:"+ele)//有些对象不能附加属性,如flash
    }
}

function zOpenD(){
    var diag 
= new Dialog("Diag1");
    diag.Width 
= 900;
    diag.Height 
= 400;
    diag.Title 
= "弹出窗口示例";
    diag.URL 
= "http://demo.zving.com/";
    diag.ShowMessageRow 
= true;
    diag.MessageTitle 
= "弹出窗口示例";
    diag.Message 
= "在这儿你可以对这个窗口的内容或功能作一些说明";
    diag.OKEvent 
= zAlert;//点击确定后调用的方法
    diag.show();
}
function zOpen(){
    var diag 
= new Dialog("Diag2");
    diag.Width 
= 900;
    diag.Height 
= 400;
    diag.Title 
= "弹出窗口示例";
    diag.URL 
= "http://demo.zving.com/";
    diag.OKEvent 
= zAlert;//点击确定后调用的方法
    diag.show();
}
function zAlert(){
        Dialog.alert(
"滤爸要来了,河谐你,河谐我,河谐二十一世纪的新一代");
}
function zConfirm(){
    Dialog.confirm(
'警告:您确认要XXOO吗?',function(){Dialog.alert("yeah,周末到了,正是好时候");});
}
function sometext(ele,n){
    var strArr
=["","","","",""];
    var writeStr
=""
    
for(i=0;i<n;i++){
        index
=parseInt(Math.random()*5);
        
for(j=0;j<5;j++){
            str
=index+j>4?index+j-5:index+j;
            writeStr
+=strArr[str];
        }
    }
    $(ele).innerHTML
=writeStr;
}
</script>
</head>
<body>
<div id="div1"></div>
<p> &nbsp;  &nbsp; <input type="button" value="弹出新窗口" onclick="zOpen()" />&nbsp;<input type="button" value="弹出带说明的新窗口" onclick="zOpenD()" />&nbsp;<input type="button" value="弹出信息提示对话框" onclick="zAlert()" />&nbsp;<input type="button" value="弹出选择对话框" onclick="zConfirm()" /></p>
<div id="div2"></div>
<script>sometext("div1",100);sometext("div2",300);</script>
</body>
</html>




Request.ServerVariables(
"Url"
返回服务器地址

Request.ServerVariables(
"Path_Info"
客户端提供的路径信息

Request.ServerVariables(
"Appl_Physical_Path"
与应用程序元数据库路径相应的物理路径

Request.ServerVariables(
"Path_Translated"
通过由虚拟至物理的映射后得到的路径

Request.ServerVariables(
"Script_Name"
执行脚本的名称

Request.ServerVariables(
"Query_String"
查询字符串內容

Request.ServerVariables(
"Http_Referer"
请求的字符串內容

Request.ServerVariables(
"Server_Port"
接受请求的服务器端口号

Request.ServerVariables(
"Remote_Addr"
发出请求的远程主机的IP地址

Request.ServerVariables(
"Remote_Host"
发出请求的远程主机名称

Request.ServerVariables(
"Local_Addr"
返回接受请求的服务器地址

Request.ServerVariables(
"Http_Host"
返回服务器地址

Request.ServerVariables(
"Server_Name"
服务器的主机名、DNS地址或IP地址

Request.ServerVariables(
"Request_Method"
提出请求的方法比如GET、HEAD、POST等等

Request.ServerVariables(
"Server_Port_Secure")
如果接受请求的服务器端口为安全端口时,则为1,否则为0

Request.ServerVariables(
"Server_Protocol")
服务器使用的协议的名称和版本

Request.ServerVariables(
"Server_Software")
应答请求并运行网关的服务器软件的名称和版本

Request.ServerVariables(
"All_Http")
客户端发送的所有HTTP标头,前缀HTTP_

Request.ServerVariables(
"All_Raw")
客户端发送的所有HTTP标头,其结果和客户端发送时一样,没有前缀HTTP_

Request.ServerVariables(
"Appl_MD_Path")
应用程序的元数据库路径

Request.ServerVariables(
"Content_Length")
客户端发出內容的长度

Request.ServerVariables(
"Https")
如果请求穿过安全通道(SSL),则返回ON如果请求来自非安全通道,则返回OFF

Request.ServerVariables(
"Instance_ID")
IIS实例的ID号

Request.ServerVariables(
"Instance_Meta_Path")
响应请求的IIS实例的元数据库路径

Request.ServerVariables(
"Http_Accept_Encoding")
返回內容如:gzip,deflate

Request.ServerVariables(
"Http_Accept_Language")
返回內容如:en
-us

Request.ServerVariables(
"Http_Connection")
返回內容:Keep
-Alive

Request.ServerVariables(
"Http_Cookie")

Request.ServerVariables(
"Http_User_Agent")
返回內容:Mozilla
/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1)

Request.ServerVariables(
"Https_Keysize")
安全套接字层连接关键字的位数,如128

Request.ServerVariables(
"Https_Secretkeysize")
服务器验证私人关键字的位数如1024

Request.ServerVariables(
"Https_Server_Issuer")
服务器证书的发行者字段

Request.ServerVariables(
"Https_Server_Subject")
服务器证书的主题字段

Request.ServerVariables(
"Auth_Password")
当使用基本验证模式时,客户在密码对话框中输入的密码

Request.ServerVariables(
"Auth_Type")
是用户访问受保护的脚本时,服务器用於检验用户的验证方法

Request.ServerVariables(
"Auth_User")
代证的用户名

Request.ServerVariables(
"Cert_Cookie")
唯一的客户证书ID号

Request.ServerVariables(
"Cert_Flag")
客户证书标誌,如有客户端证书,则bit0为0如果客户端证书验证无效,bit1被设置为1

Request.ServerVariables(
"Cert_Issuer")
用户证书中的发行者字段

Request.ServerVariables(
"Cert_Keysize")
安全套接字层连接关键字的位数,如128

Request.ServerVariables(
"Cert_Secretkeysize")
服务器验证私人关键字的位数如1024

Request.ServerVariables(
"Cert_Serialnumber")
客户证书的序列号字段

Request.ServerVariables(
"Cert_Server_Issuer")
服务器证书的发行者字段

Request.ServerVariables(
"Cert_Server_Subject")
服务器证书的主题字段

Request.ServerVariables(
"Cert_Subject")
客户端证书的主题字段

Request.ServerVariables(
"Content_Type")
客户发送的form內容或HTTPPUT的数据类型

转载于:https://www.cnblogs.com/z2002m/archive/2009/07/12/1522123.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值