| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 548 人关注过本帖
标题:[原创] 向高手求助
只看楼主 加入收藏
met116
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2005-11-19
收藏
 问题点数:0 回复次数:0 
[原创] 向高手求助

下面是一个留言板的程序,找了很久,不知道到底是哪里错了,高手请指教,数据库是用Access建的:
用户输入页面文件:
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=GB2312">
<meta http-eqiv="content-Language" content="zh-cn">
<title>心情留言板</title>
</head>
<body background="00ffff"><font color="Blue">
<center>
<h1>
<font color="blue">
心情留言板
</font>
</h1>
<hr>
<form action=ex17_01a.jsp method=post>
<table border=1>
<tr>
<td bgcolor=pink>姓名:</td>
<td>
<input type=text size=20 name=name>
</td>
</tr>
<tr>
<td bgcolor=pink>主题:</td>
<td>
<input type=text size=60 name=title>
</td>
</tr>
<tr>
<td valign=top bgcolor=pink>留言:</td>
<td><textarea name=msg rows=4 cols=60></textarea></td>
</tr>
<tr align=center>
<td colspan=2>
<input type=submit name=send value=发送>
<input type=reset value=我要重写>
</td>
</tr>
</table>
</form>
<hr>
<a href=ex17_01b.jsp>回留言看板</a>
</center>
</body>
</html>

把留言提交给数据库的jsp文件:
<%@ page language="java" %>
<%@ page info="database handler" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
//<%@ page import="javax.servlet.*" %>
//<%@ page import="javax.servlet.http.*" %>
<%@ page contentType="txet/html;charset=gb2312" %>

<%!
String ToGB2312(String str)
{
byte GB2312[]=new byte[str.length()];
for(int i=0;i<str.length();i++)
{
GB2312[i]=(byte)str.charAt(i);
}
return new String(GB2312);
}
String CutLine(String str)
{
int indx=0;
while((indx=str.indexOf("\n"))!=-1)
{
str=str.substring(o,indx);
str=str+"<br>"+str.substring(indx+1);
}
return(str);
}
%>
<%!
String DBName="Borard" ;
String Table="SimpleMsg";
Connection con=null;
Statement stmt=null;
ResultSet res=null;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
out.print(e.toString());
}

try{
con=DriverManager.getConnection("jdbc:odbc:mydata","","");

stmt=con.createStatement();

String sql="";
String name="";
String title="";
String msg="";
name=request.getParameter("name");
title=request.getParameter("title");
msg =request.getParameter("msg");
boolean correct=true;
int err=0;
int erridx=0;
String errmsgs[]=new String[20];
if(name.length()==0)
{
correct=false;
errmsgs[err]="无名?至少给我个名字吧!";
err++;
}
if(title.length()==0)
{
correct=false;
errmsgs[err]="留言板没有主题哟";
err++;
}
if(msg.length()==0)
{
correct=false;
errmsgs[err]="留言板地方不可以留白啦";
err++;
}
out.println("<h1><center>");
out.println("<font color=\"blue\">");
out.println("发生错误信息</font>");
out.println("<hr></h1>");

if(correct==false)
{
for(erridx=0;erridx<err;erridx++)
{
out.println("<font color=red>");
out.println(errmsgs[erridx]+"</font><br>");
}

out.println("<hr><br><a href=ex17_01b.jsp>[我要看别人的留言]</a>");
out.println("<br><a href=ex17_01.jsp>[回留言板看]");
out.println("</center>");
}
else
{
int count=0;
int point=0;

name=ToGB2312(name);
title=ToGB2312(title);

//msg=CutLine(msg);
msg=ToGB2312(msg);

sql="insert into"+Table+"set name='";
sql=sql+name+"',title='"+title;
sql=sql+"',msg='"+msg+"'";

stmt.executeQuery(sql);
sql="select *from"+Table;
res=stmt.executeQuery(sql);
while(res.next())
{
count++;
}
response.sendRedirect("ex17_01b.jsp?pagenum="+point);
}
}

catch(SQLException e)
{
e.toString();
}

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<title> 输入资料有误处理网页</title>
</head>
<body background="00ffff"><font color="blue">
</body>
</html>

查看所有留言的页面:
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=gb2312" %>
<%!
String ToGB2312(String str)
{
byte GB2312[]=new byte[str.length()];
for(int i=0;i<str.length();i++)
{
GB2312[i]=(byte)str.charAt(i);
}
return new String(GB2312);
}
String CutLine(String str)
{
int indx=0;
while((indx=str.indexOf("\n"))!=-1)
{
str=str.substring(o,indx);
str=str+"<br>"+str.substring(indx+1);
}
return(str);
}
%>

<%!
String DBName="Board";
String Table="SimpleMsg";

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
out.print(e.toString());
}

try
{
Connection.con=DriverManager.getConnetion("jdbc:odbc:mydata","","");
Statement stmt=con.createStatement();
ResultSet res;
String sql="";
int count=0,over,nf,n1,up,down,pagenum;
if(request.getParameter("pagenum")==null)
{
pagenum=0;
}
else
{
pagenum=Integer.parseInt(request.getParameter("pagenum"));
}

sql="select * from"+Table;
res=stmt.executeQuery(sql);

while(res.next())
{
count++;
}
over=(int)Math.ceil((double)count/3);

if(pagenum==0||pagenum>over)
{
pagenum=over;
}
nf=pagenum+3-2;
n1=nf+2;

if(pagenum==1)
{
up=1;
}
else
{
up=pagenum-1;
}
if(pagenum==over)
{
down=over;
}
else
{
down=pagenum+1;
}

sql="select * from"+Table;
sql=sql+" where idx between"+nf+"and"+n1;

res=stmt.executeQuery(sql);
}
catch(SQLException e1)
{

}

%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<title>心情留言板</title>
</head>
<body bgcolor="red"><font color="blue" size=""></body>
<center>
<h1>

<font color="blue">
心情留言板
</font>
</h1>
<hr>
<center>
<a href=ex17_01b.jsp?pagenum=1>/第一页/</a>
<a href=ex17_01b.jsp?pagenum=<%=up%>>/上一页/</a>
<a href=ex17_01b.jsp?pagenum=<%=down%>>\下一页\</a>
<a href=ex17_01b.jsp>\最后一页\</a>
<form action=ex17_01b.jsp method=post>
<table border=0>
<tr>
<td>
<font color=blue>页次:[</font>
<font color=red><%=pagenum%></font>
<font color=blue>/<%=over%>]</font>
</td>
<td>页
<input type=submit name=send value=发送>
</td>
<td>
</tr>
</table>
</form>
<%
String name="";
String title="";
String msg="";
while(res.next());
{
name= res.getString(1);
title=res.getString(2);
msg=res.getString(3);
out.println("<table border=1>");

out.println("<tr><td bgcolor=pink>作者</td><td>");
out.println(name+"</td></tr>");

out.println("<tr><td bgcolor=pink>文章标题</td><td>");
out.println(title+"</td></tr>");

out.println("<tr><td bgcolor=pink>作者</td><td>");
out.println(msg+"</td></tr>");

out.println("</table><br>");

}
%>


<hr>

<a href=ex17_01.jsp>我要留言</a>
<a href=ex17_01b.jsp>重新整理</a>

</body>
</html>




[此贴子已经被作者于2005-12-22 18:46:04编辑过]

2005-12-22 16:52
快速回复:[原创] 向高手求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018967 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved