学习Jsp小结?
学了这么久jsp,做了一个新闻发表系统作为总结。
新闻发表首页:
fabiao.htm:
<%@page contentType="text/html;charset=gb2312"%>
<%request.setCharacterEncoding("GB2312");%>
<%@include file="head.htm"%>
<html>
<head>
<title>zhangzl</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<%@include file="head.htm"%>
<body bgcolor="#F4F4F4" text="#000000">

<div align="center">
<Script LANGUAGE="JavaScript">
function formCheck()
{
if (document.theform.title.value == "")
{
alert("请填写标题!");
return false;
}
if (document.theform.keyw.value == "")
{
alert("请填写新闻关键字!");
return false;
}
if (document.theform.author.value == "")
{
alert("请填写您的名字!");
return false;
}
if (document.theform.content.value == "")
{
alert("请填写您的新闻内容!");
return false;
}
}
</Script>
<font face="华文中宋"><b><font size="6" color="#FF0000">发表新闻</font></b></font><br>
</div>
<form NAME="theform" ACTION="insert.jsp" METHOD="post" onSubmit="return formCheck()">
<table width="36%" border="1" height="228" align="center" bgcolor="#CCCCCC">
<tr>
<td width="18%"><font color="#3333FF">标题:</font></td>
<td colspan="2">
<input type="text" name="title">
</td>
</tr>
<tr>
<td width="18%"><font color="#3333FF">关键字: </font></td>
<td colspan="2">
<input type="text" name="keyw">
</td>
</tr>
<tr>
<td width="18%"><font color="#3333FF">作者:</font></td>
<td colspan="2">
<input type="text" name="author">
</td>
</tr>
<tr>
<td width="18%" align="left" valign="bottom"><font color="#3333FF">内容:</font></td>
<td colspan="2">
<textarea name="content" cols="25" rows="5"></textarea>
</td>
</tr>
<tr>
<td height="50" width="18%">
<div align="left">
<input type="submit" name="go" value="o k">
</div>
</td>
<td height="50" width="42%">
<input type="reset" name="Submit2" value="Reset">
<a href = "show.jsp"> </a></td>
<td height="50" width="40%"><a href = "show.jsp"><font color="#FF0000">查看新闻</font></a></td>
</tr>
</table>
<%@include file="footer.htm"%>
<br>
<br>
</form>
<p> </p>
</body>
</html>

------

回复此文章 |
回复主题:Re:学习Jsp小结? | 作者:lunzi | 军衔:六级军士 | 发表时间:2004-10-30 12:26:26
插入新闻页面:
insert.jsp:
<%@page contentType="text/html;charset=gb2312"%>
<%@ include file="inc.jsp" %>
<%
String stitle = request.getParameter("title");
String Date= request.getParameter("Date");
String sbody = request.getParameter("content");
String semail = request.getParameter("keyw");
String stel = request.getParameter("author");
java.util.Date date=new java.util.Date();
int yyyy=1900+date.getYear();
int mm=date.getMonth()+1;
int dd=date.getDate();
int hh=date.getHours();
int mi=date.getMinutes();
int ss=date.getSeconds();
Date= yyyy+"-"+mm+"-"+dd+" "+hh+":"+mi+":"+ss;
boolean go;
sql="insert into new_sz (title,Date,content,keyw,author) values (' "+stitle+" ',' "+Date+" ',' "+sbody+" ',' "+semail+" ',' "+stel+" ')";
//out.println(sql);
go = apple.insert(sql);
if(go)
out.println("");
else
out.println("Failed.");
apple.closeConn();
%><title>新闻插入</title>
<body bgcolor="#F4F4F4">
<div align="center"><br>
<b><font size="6" face="华文中宋" color="#FF0000">恭喜你~~!!</font></b><br>
</div>
<table width="50%" border="1" align="center" bgcolor="#E7E7E7">
<tr>
<td width="42%"><font color="#0033FF">新闻发表成功!!</font></td>
<td width="58%"> </td>
</tr>
<tr>
<td width="42%"><font color="#0033FF">看看去!!</font></td>
<td width="58%"><a href = "show.jsp"><font color="#FF0000">查看新闻</font></a>
<a href="fabiao.htm"><font color="#FF0000">继续发布</font></a></td>
</tr>
</table>

------

回复此文章 |
回复主题:Re:Re:学习Jsp小结? | 作者:lunzi | 军衔:六级军士 | 发表时间:2004-10-30 12:27:39
查看新闻页面:
show.jsp:
<%@page contentType="text/html;charset=GB2312"%>
<%@include file="inc.jsp"%>
<Script language="JavaScript">
//打开新窗口函数NewsWindow
function NewsWindow(id)
{
window.open('newswind.jsp?id='+id,'infoWin', 'height=400,width=600,scrollbars=yes,resizable=yes');
}
</Script>
<%
sql="select * from new_sz order by id desc";
rs=apple.select(sql);
%>
<html>
<head>
<title>新闻</title>
</head><%@include file="head.htm"%>
<body bgcolor="#999999">
<table border=1 align='center' width='71%'>
<tr>
<td width="47%">
<div align="center">主题</div>
</td>
<td width="21%">
<div align="center">作者</div>
</td>
<td width="32%">
<div align="center">时间</div>
</td>
</tr>
<%
while(rs.next() )
{
%>
<%
int cc = 1;
do {
// 不同行之间以不同颜色显示
if(cc % 2 == 1)
out.println("<tr bgcolor=#E7E7E7>");
else
out.println("<tr BGCOLOR=#F4F4F4>");
%>
<td width="47%"><a href="javascript:NewsWindow(<%=rs.getInt("ID")%>)"><u>
<%String title=rs.getString("title");
title=new String(title.getBytes("ISO-8859-1"),"GB2312" );
%>
<%=title%></u></a></td>
<td width="21%" align="center">
<%String author=rs.getString("author");
author=new String(author.getBytes("ISO-8859-1"),"GB2312" );
%>
<%=author%>
<div align="center"></div>
</td>
<td width="32%" align="center"><%=rs.getString("Date")%>
<%
out.println("</td></tr>");
cc++;
} while(rs.next());
%>
<%
}
apple.closeConn();
%>
<div align="center"></div>

</table>
<%@ include file="footer.htm" %>
</body>
</html>
------

回复此文章 |
回复主题:Re:Re:Re:学习Jsp小结? | 作者:lunzi | 军衔:六级军士 | 发表时间:2004-10-30 12:29:33
主题下新闻的主要内容:
newswind.jsp:
<%@page contentType="text/html;charset=GB2312"%>
<%request.setCharacterEncoding("GB2312");%>
<%@include file="inc.jsp"%>
<Script language="JavaScript">
//打开新窗口函数NewsWindow
function NewsWindow(id)
{
window.open('newswind.jsp?id='+id,'infoWin', 'height=400,width=600,scrollbars=yes,resizable=yes');
}
</Script>
<%
String id;
id=request.getParameter("id");
sql="select * from new_sz where id="+id ;
rs=apple.select(sql);
%>
<html>
<head>
<title>留言测试</title>
</head>
<body>
<table width="100%" HEIGHT=100% border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">


<%
while(rs.next() )
{
%>



<tr bgcolor="#FAD195">
<td height=20 align=center><b><%String title=rs.getString("title");
title=new String(title.getBytes("ISO-8859-1"),"GB2312" );
%><%=title%>
</b></td>
</tr>
<tr>
<td valign=top>
<p><%String content=rs.getString("content");
content=new String(content.getBytes("ISO-8859-1"),"GB2312" );
%><%=content%>
</tr>

<%
}
apple.closeConn();
%>
</table>
<br><b>相关新闻:</b><ul>
</body>
</html>
------
如果我的出现,令你惊喜,我庆幸我们能成为朋友。
如果我的出现,令你烦恼,请恕我无意。如果你想,我愿意淡出我的生活。
但是,我永远也不会忘记,因为你是我的唯一。
回复此文章 |
回复主题:Re:Re:Re:Re:学习Jsp小结? | 作者:lunzi | 军衔:六级军士 | 发表时间:2004-10-30 12:35:02
页头:
head.htm:
<%@page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>新闻</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#999999" text="#000000">
<table width="71%" border="1" align="center">
<tr align="center">
<td width="47%"><a href="fabiao.htm">发表文章</a></td>
<td width="21%"><a href="admin.jsp">删除新闻</a></td>
<td width="32%"><a href="show.jsp">查看新闻</a></td>
</tr>
</table>
</body>
</html>
页脚:
footer.htm
<%@page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>新闻t</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#999999" text="#000000">
<table width="71%" border="1" align="center">
<tr align="center">
<td>CopyRight@2004 北京卓达经管学院 <br>
设计:lunzi--2004.10</td>
</tr>
</table>
</body>
</html>

hofman   2005-11-19 22:18:14 评论:0   阅读:1922   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog