Project function: Realize the function of the General BBS Forum Project, publish say that other friends can comment
First, the creation of the database:
The SQL statements are as follows:
create table Span class= "hljs-string" > ' BBS ' . ' user ' ( int not< /span> null auto_increment, ' username ' char (20 ) not null , ' UserPassword ' CHAR (20 ) not null , primary key ()); Create unique index ' PRIMARY ' on ' BBS '. ' user ' (' userid ');
Create Table ' BBS '.' article '(' ArticleID ' INT not NULLAuto_increment,' title ' CHAR( -) not NULL,' context ' CHAR( $) not NULL,' Articletime ' Time not NULL,' userid ' INT not NULL,Primary Key(' ArticleID ') ); alter table ' BBS '. ' article ' Add index ' article_user_fk '(' userid '), add constraint ' Artic LE_USER_FK 'foreign key (' userid ') references ' BBS '.
' user '(
' userid ');
Create unique index ' PRIMARY ' on ' BBS '. ' article ' (' ArticleID '); Create index ' article_user_fk ' on ' BBS '. ' article ' (' userid ');
Create Table ' BBS '.' comment '(' Commentid ' INT not NULLAuto_increment,' Commenttext ' CHAR( $) not NULL,' Commenttime ' Time not NULL,' userid ' INT not NULL,' ArticleID ' INT not NULL,Primary Key(' Commentid ') ); alter table Span class= "hljs-string" > ' BBS ' . ' comment ' add index ' COMMENT_ARTICLE_FK ' ( ' ArticleID ' ), add constraint
' COMMENT_ARTICLE_FK ' foreign key ( ' ArticleID ' ) references
' BBS ' . ' article ' ( ' ArticleID ' ); alter table Span class= "hljs-string" > ' BBS ' . ' comment ' add index ' COMMENT_USER_FK ' ( ), add Constraint ' COMMENT_USER_FK ' foreign key () refere NCEs . ' user ' (); Create unique index ' PRIMARY ' on ' BBS '. ' comment ' (' Commentid '); Create index ' comment_user_fk ' on ' BBS '. ' comment ' (' userid '); Create index ' comment_article_fk ' on ' BBS '. ' comment ' (' ArticleID ');
Second, the project code is as follows:
The main implementation of the code: solve the problem of Chinese garbled:
Public class myfilter implements Filter { PrivateString encoding=NULL; Public void DoFilter(ServletRequest arg0, Servletresponse arg1, Filterchain arg2)throwsIOException, Servletexception {arg0.setcharacterencoding (encoding); Arg2.dofilter (arg0, arg1); } Public void Init(Filterconfig arg0)throwsservletexception {encoding = Arg0.getinitparameter ("Encoding");//Get encoding in the configuration file} Public void Destroy() { }}
configuring in the Web. xml file
<!--filter Chinese garbled problems-- <filter> <filter-name>Myfilter</filter-name> <filter-class>Com.xuliugen.util.MyFilter</filter-class> <init-param> <param-name>Encoding</param-name> <param-value>Utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>Myfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
All code here: http://download.csdn.net/detail/u010870518/8570147
Jsp-servlet realization of online BBS project small case