开源里有没有留言板的源代码,JAVA的绝对开源,绝对明了的留言板,便于学习的源码
用JAVA写的留言板原代码
/*
* guestbookServlet.java
*
* */
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.Date;
/**
*
* */
public class guestbookServlet extends HttpServlet {
boolean debug=false;
String sDBDriver;
Connection conn=null;
ResultSet rs=null;
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
if(debug)
sDBDriver=new String("sun.jdbc.odbc.JdbcOdbcDriver");
else
sDBDriver=new String("org.gjt.mm.mysql.Driver");
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("Driver类初始化:"+e.getMessage());
}
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Processes requests for both HTTP codeGET/code and codePOST/code methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html;charset=gb2312");
java.io.PrintWriter out = response.getWriter();
boolean empty=true;
boolean noResult=true;
String sqlStr;
int currentPage=0;
int totalPage=0;
int reccount=0;
ResultSet myrs=null;
String username=request.getParameter("username");
String email=request.getParameter("email");
String ucontent=request.getParameter("ucontent");
String ipage=request.getParameter("ipage");
if(ipage==null||ipage.length()==0)
currentPage=1;
else
currentPage=Integer.parseInt(ipage);
if((username==null||username.length()==0)||(ucontent==null||ucontent.length()==0))empty=true;
else empty=false;
Date myDate=new Date();
//String intime=new String(String.valueOf(myDate.getYear()+1990)+String.valueOf(myDate.getMonth()));
String year=String.valueOf(myDate.getYear()+1900);
String month=String.valueOf(myDate.getMonth()+1);
if(month.length()==1)
month=new String("0"+month);
String days=String.valueOf(myDate.getDate());
if(days.length()==1)
days=new String("0"+days);
String hours=String.valueOf(myDate.getHours());
if(hours.length()==1)
hours=new String("0"+hours);
String minutes=String.valueOf(myDate.getMinutes());
if(minutes.length()==1)
minutes=new String("0"+minutes);
String intime=year+"-"+month+"-"+days+" "+hours+":"+minutes;
if(email==null||email.length()==0)
email=new String("");
if(!empty){
//username=convert(username);
//email=convert(email);
//ucontent=convert(ucontent);
sqlStr="insert into Mintegbook(Mname,Memail,Mcontent,Mtime,Mid) values("+username+","+email+","+ucontent+","+intime+",1)";
getDsnConn();
executeInsert(sqlStr);
}
sqlStr=new String("select Mname,Memail,Mcontent,Mtime from Mintegbook order by Mtime DESC");
getDsnConn();
reccount=getRecordCount("Mintegbook");
if(reccount==0)
noResult=true;
else
noResult=false;
if(!noResult){
int ipageSize=10;
totalPage=getTotalPage("Mintegbook",ipageSize);
if(currentPagetotalPage)
currentPage=totalPage;
int cursor=(currentPage-1)*ipageSize+1;
try{
myrs=executeScrollableQuery(sqlStr);
myrs.absolute(cursor);
}
catch(SQLException e){
noResult=true;
}
}
out.println("HTMLHEADTITLE我的Servlet留言板/TITLE");
out.println("META http-equiv="Content-Type" content="text/html; charset=gb2312"");
out.println("STYLE type="text/css"");
推荐阅读
- 快手直播礼物可以挣多少,快手直播礼物主播能拿多少
- 包含华为nava7pro鸿蒙系统升级的词条
- oracle安装之后怎么启动不了,安装完oracle
- 快速设置代理,设置代理快捷键
- python传入比较函数 python比较语句
- sap成品扫描入库流程,sap成品入库操作
- 即时战略游戏seas,即时战略游戏手游
- php翻转数据库数据 php数据迁移
- 关于ecshopjquery冲突的信息