仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1077|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET网站制作之.NET旧事公布天生静态页面并完成分页

[复制链接]
跳转到指定楼层
楼主
发表于 2015-1-16 22:24:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
也不知道,我同学昨天说数据挖掘很好。.NET旧事公布天生静态页面并完成分页1、静态模板页面template.html,次要是界说了一些特别字符,用来被交换。
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title>$Title</title>
</head>
<body>
<divstyle="width:417px;height:54px"align="center">
<br/>
$Title</div>
<divstyle="width:417px;height:8px">
扫瞄<fontcolor="red"><scriptsrc="http://localhost/.Net/NewsFiles/ClickCount.aspx?NewsId=$NewsId"></script></font>次$Time</div>
<divstyle="width:417px;height:100px">
$Content</div>
<divstyle="width:416px;height:9px">
$Pager</div>
<divstyle="width:416px;height:8px">
<formid="form1"action="../AddComment.aspx"style="margin:0px">
<inputid="Text1"type="text"/></textarea>
<br/>
<inputid="NewsId"type="hidden"value="$NewsId"/>
<inputid="Button1"type="submit"value="button"/>
<ahref="../Display.aspx?NewsId=$NewsId">检察更多批评</a></form>
</div>
</body>
</html>
2、前态页面NewsAdd.aspx,就是一个表单,用来填写旧事的题目和内容。
<%...@PageLanguage="C#"AutoEventWireup="false"validateRequest="false"CodeFile="NewsAdd.aspx.cs"Inherits="NewsAdd.Admin_AdminPanel_NewsAdd"%>
<%...@RegisterTagPrefix="FCKeditorV2"Namespace="FredCK.FCKeditorV2"Assembly="FredCK.FCKeditorV2"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>增加旧事</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:LabelID="Label2"runat="server"Text="题目"></asp:Label>
<asp:TextBoxID="Title"runat="server"Width="325px"></asp:TextBox><br/>
<asp:LabelID="Label1"runat="server"Text="内容"></asp:Label>
<FCKeditorV2:FCKeditorid="Content"basePath="~/FCKeditor/"runat="server"Height="400px"Width="70%"></FCKeditorV2:FCKeditor>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>
<asp:LabelID="Message"runat="server"></asp:Label></div>
</form>
</body>
</html>
3、背景页面NewsAdd.aspx.csusingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingMysqlserver;
usingSystem.IO;
usingSystem.Text;
namespaceNewsAdd
...{
publicpartialclassAdmin_AdminPanel_NewsAdd:System.Web.UI.Page
...{
protectedvoidPage_Load(objectsender,EventArgse)
...{
}
protectedvoidButton1_Click(objectsender,EventArgse)
...{
stringstrDate=DateTime.Now.ToString("yyMMdd")+""+DateTime.Now.ToString("yyyymmddhhmmss");
stringstrFileName=strDate+".shtml";//存储到数据库中
stringstrTitle=Request.Form["Title"].ToString().Trim();//吸收传过去的题目
stringstrContent=Request.Form["Content"].ToString().Trim();//吸收传过去的内容
string[]content=strContent.Split(newChar[]...{});//对内容举行拆分,并保留到数组
intupbound=content.Length;//数组的下限
SqlServerDataBasedb=newSqlServerDataBase();
boolsuccess=db.Insert("insertintoinNews(Title,Content,FilePath)values("+strTitle+","+strContent+","+strFileName+")",null);
//if(success)
//Message.Text="增加乐成!";
/**////////////////////////////创立以后日期的文件夹入手下手
stringdir=Server.MapPath("../../"+"NewsFiles/"+DateTime.Now.ToString("yyMMdd"));//用来天生文件夹
if(!Directory.Exists(dir))
...{
Directory.CreateDirectory(dir);
}
/**////////////////////////////创立以后日期的文件夹停止
try
...{
for(inti=0;i<content.Length;i++)
...{
//string[]newContent=newstring[4];//界说和html标志数量分歧的数组
StringBuilderstrhtml=newStringBuilder();
//创立StreamReader工具
using(StreamReadersr=newStreamReader(Server.MapPath("../../"+"NewsFiles/")+"        emplate.html",Encoding.GetEncoding("gb2312")))
...{
Stringoneline;
//读取指定的HTML文件模板
while((oneline=sr.ReadLine())!=null)
...{
strhtml.Append(oneline);
}
sr.Close();
}
//为标志数组赋值
//SqlServerDataBasedb=newSqlServerDataBase();
DataSetds=db.Select("selecttop1NewsIdfrominNewsorderbyNewsIddesc",null);//猎取id
stringstrTable="<table><tr><td>$upUrl</td><td>$Number</td><td>$downUrl</td></tr></table>";//高低页表格,注重此处的$upUrl(上一页),$Number(页码分页),$downUrl(下一页)
//这三个是用来交换的。
stringFilePath="";
strhtml=strhtml.Replace("$Title",strTitle);
strhtml=strhtml.Replace("$NewsId",ds.Tables[0].Rows[0]["NewsId"].ToString());
strhtml=strhtml.Replace("$Time",DateTime.Now.ToString("yyyy/MM/dd"));
strhtml=strhtml.Replace("$Content",content[i]);
stringstrNumber="";//数字分页1,2,3……
for(intm=1;m<=upbound;m++)
...{
if(m==1)//假如是第一页就显现成这个模样:20070524.shtml而不是20070524_1.shtml
strNumber=strNumber+"["+"<ahref="+"../"+strDate+".shtml"+">"+m+"</a>"+"]";
else
...{
intn=m-1;//第三页的毗连应当是20070524_2.shtml,以此类推
strNumber=strNumber+"["+"<ahref="+"../"+strDate+"_"+n+".shtml"+">"+m+"</a>"+"]";
}
}
if(upbound==0)//假如没有分页,就间接按日期工夫保留
...{
FilePath=Server.MapPath("../../")+"NewsFiles"+"//"+strDate+".shtml";
strhtml=strhtml.Replace("$Pager","");
}
else//不然按20070524.shtml、20070524_1.shtml这类效果保留
...{
if(i==0)
FilePath=Server.MapPath("../../")+"NewsFiles"+"//"+strDate+".shtml";
else
FilePath=Server.MapPath("../../")+"NewsFiles"+"//"+strDate+"_"+i+".shtml";

if(i==0)//第一页不显现上一页
strTable=strTable.Replace("$upUrl","");
if(i<=1)//上一页分页
strTable=strTable.Replace("$upUrl","<ahref="+"../"+strDate+".shtml"+">上一页</a>");
else
...{
intp=i-1;
strTable=strTable.Replace("$upUrl","<ahref="+"../"+strDate+"_"+p+".shtml"+">上一页</a>");
}

if(upbound==1)//假如只要一页,则不显现页码
//strNumber="";
strTable=strTable.Replace("$Number","");
else
strTable=strTable.Replace("$Number",strNumber);//页码交换
/**/////////////////////////
if(i==upbound-1)//最初一页不显现下一页
strTable=strTable.Replace("$downUrl","");
if(i!=upbound-1)//下一页分页
...{
intq=i+1;
strTable=strTable.Replace("$downUrl","<ahref="+"../"+strDate+"_"+q+".shtml"+">下一页</a>");
}
else
...{
intj=upbound-1;
strTable=strTable.Replace("$downUrl","<ahref="+"../"+strDate+"_"+j+".shtml"+">下一页</a>");
}
strhtml=strhtml.Replace("$Pager",strTable);
}
//创立文件信息工具--------------------------------------------
FileInfofinfo=newFileInfo(FilePath);
//以翻开大概写进的情势创立文件流
using(FileStreamfs=finfo.OpenWrite())
...{
//依据下面创立的文件流创立写数据流
StreamWritersw=newStreamWriter(fs,System.Text.Encoding.Default);
//把新的内容写到创立的HTML页面中
sw.WriteLine(strhtml);
sw.Flush();
sw.Close();
}
}
}
catch(Exceptionerr)
...{
//输入非常信息
Response.Write(err.ToString());
}
}
}
}

其实Java之所以在曾经独步天下,就是因为他的跨平台、安全性,这两方面,效率可不是Java的强项,反而是他最短的一块挡板,虽然net总是用理论证明比.NET快。
谁可相欹 该用户已被删除
沙发
发表于 2015-1-19 10:47:12 | 只看该作者
是目前ASP在UNIX/Linux上的应用可以说几乎为0)。所以平台的局限性和ASP自身的安全性限制了ASP的广泛应用。
板凳
 楼主| 发表于 2015-1-28 06:08:01 | 只看该作者
使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行,用户端的浏览器不需要提供任何别的支持,这样大提高了用户与服务器之间的交互的速度。
admin 该用户已被删除
地板
发表于 2015-2-5 19:09:11 | 只看该作者
Servlet却在响应第一个请求的时候被载入,一旦Servlet被载入,便处于已执行状态。对于以后其他用户的请求,它并不打开进程,而是打开一个线程(Thread),将结果发送给客户。由于线程与线程之间可以通过生成自己的父线程(ParentThread)来实现资源共享,这样就减轻了服务器的负担,所以,JavaServlet可以用来做大规模的应用服务。
不帅 该用户已被删除
5#
发表于 2015-2-13 06:58:59 | 只看该作者
当然我们在选择Asp.net主机是,除了要考虑服务提供商在版本是否是实时更新以外,机房的环境和配置也是非常重要的,通常选择骨干网的机房,在速度和稳定性上会非常有保证。
莫相离 该用户已被删除
6#
发表于 2015-3-3 19:05:47 | 只看该作者
ASP.net1.1和2.0在程序上的语法也有很大不同,现在2.0属于新出来的,不知道半年后会不会有3.0(说笑一下)。Windows2003系统自动支持ASP和ASP.net环境,不用安装任何程序。Asp.net属于编译语言。ASP的最大不同(ASP属于解释语言)。
简单生活 该用户已被删除
7#
发表于 2015-3-11 12:49:00 | 只看该作者
那么,ASP.Net有哪些改进呢?
爱飞 该用户已被删除
8#
发表于 2015-3-18 19:41:27 | 只看该作者
PHP的源代码完全公开,在OpenSource意识抬头的今天,它更是这方面的中流砥柱。不断地有新的函数库加入,以及不停地更新,使得PHP无论在UNIX或是Win32的平台上都可以有更多新的功能。它提供丰富的函数,使得在程式设计方面有着更好的资源。目前PHP的最新版本为4.1.1,它可以在Win32以及UNIX/Linux等几乎所有的平台上良好工作。PHP在4.0版后使用了全新的Zend引擎,其在最佳化之后的效率,比较传统CGI或者ASP等技术有了更好的表现。
海妖 该用户已被删除
9#
发表于 2015-3-26 14:46:29 | 只看该作者
通过这次激烈的讨论,我从大家身上学到了太多,开阔了眼界,不管是支持我的还是骂我的,都感谢你们。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-4 20:51

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表