Jsp+mysql make a simple message board (1)

Source: Internet
Author: User
Tags count integer numeric mysql prev mysql database
Js|mysql Message Board to achieve the function is: browsing people can leave a message and can be divided into pages to view the message, the administrator can handle the message!
This message board is composed of 9 small programs, namely: board.jsp;message.html;opendata.jsp;manager.jsp;password.jsp;check.jsp;delete.jsp; convert.jsp
Now, the first one: board.jsp.
His task is the entire message board's main program, lets the user leave a message, and provides the paging function!
Before we start, we have to build a mydate database in the MySQL database and create a table named message in Mudate:
Mysql>create Table Message (name char), email char, subject char (a), Time char (a), sex char (), Memo Text,id int Not NULL Auto_increment,primary key (ID));

Board.jsp Code:
<HTML>
<HEAD>
<TITLE> Gossip Board </TITLE>

</HEAD>
<BODY>
<%@ page import= "java.sql.*"%>
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ include file= "opendata.jsp"%>
<%
int Count=0,lastp,numf,numl,prep,nextp,pageno;
if (Request.getparameter ("PageNo") ==null)//pageno: Representative page number
pageno=0;
Else
Pageno=integer.parseint (Request.getparameter ("PageNo"));
Sql= "SELECT * from Message";
Rs=smt.executequery (SQL);
while (Rs.next ())
count++; <%--Count: How many messages--%>
lastp= (int) Math.ceil (double) COUNT/5);
<%--is used to calculate the number of pages in this table message: Ceil returns the smallest integer greater than or equal to its numeric parameter.

Math.ceil (number)

The required number argument is a numeric expression.

Description
Returns the smallest integer with a value greater than or equal to its numeric parameter. --%>
if (pageno==0| | PAGENO&GT;LASTP)
PAGENO=LASTP;
numf=pageno*5-4; <%--Displays the number of the first data for the message _id--%>
NUML=NUMF+4;&LT;%--NUML: The last data number for this page id--%>
if (pageno==1)
Prep=1; <%--Prep: Prev--%>
Else
Prep=pageno-1;
if (PAGENO==LASTP)
NEXTP=LASTP;
Else
nextp=pageno+1;
Sql= "SELECT * from message where ID between" +numf+ "and" +NUML;
Rs=smt.executequery (SQL);

%>

<font size=7 color=green> Message Board </font>
<center>
<form action=board.jsp method=post>
<table boder=0>
<tr>
<td> Current page <font Color=red><%=pageno%></font>/<font color=blue><%=lastp%></ Font></td>
<td><a href=board.jsp?pageno=<%=prep%>>[prev]</a></td>
<%--passes the parameter pageno to the program, calculates NUML and NUMF based on it, and then extracts the message data through SQL--%>
<td><a href=board.jsp?pageno=<%=nextp%>>[Next Page]</a></td>
<td><a href=board.jsp?pageno=1>[First Page]</a></td>
<td><a href=board.jsp>[last page]</a></td>
<td> Input page times <input type=text size=3 name=pageno></td>
<td><input type=submit name=send value= send out ></td>
<td><a href=password.jsp><font color=red size= "5" ><i> webmaster dedicated </i></font></a ></td>
</tr>
</table>
</form>
<%
String Name,email,subject,time,sex,memo;
while (Rs.next ())
{
Name=rs.getstring (1);
Email=rs.getstring (2);
Subject=rs.getstring (3);
Time=rs.getstring (4);
Sex=rs.getstring (5);
Memo=rs.getstring (6);
Out.print ("<center>");
Out.print ("<table border=1>");
Out.print ("&LT;TR&GT;&LT;TD bgcolor=yellow> name </td><td>" +name+ "</td></tr>");
Out.print ("<tr><td bgcolor=yellow>e-mail</td><td>" +email+ "</td></tr>");
Out.print ("<tr><td bgcolor=yellow> time </td><td>" +time+ "</td></tr>");
Out.print ("<tr><td bgcolor=yellow> theme </td><td>" +subject+ "</td></tr>");
Out.print ("&LT;TR&GT;&LT;TD bgcolor=yellow> message </td><td> +memo+" </td> </tr> ");
Out.print ("</table><p>");

}
%>
<center><a href= "message.html" > I want to leave a message </a>
<a href=board.jsp> View Message </a>

</BODY>
</HTML>






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.