Use JSP-Servlet to implement online BBS project, and use jsp-servlet online

Source: Internet
Author: User

Use JSP-Servlet to implement online BBS project, and use jsp-servlet online

Project function: implements the function of common bbs Forum projects. Comments can be posted to other friends.

1. Create a database:

The SQL statement is as follows:

    create table `bbs`.`user`(        `userid` INT not null auto_increment,       `username` CHAR(20) not null,       `userpassword` CHAR(20) not null,        primary key (`userid`)    );    create unique index `PRIMARY` on `bbs`.`user`(`userid`);
    create table `bbs`.`article`(        `articleid` INT not null auto_increment,       `title` CHAR(50) not null,       `context` CHAR(200) 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 `article_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 null auto_increment,       `commenttext` CHAR(200) not null,       `commenttime` TIME not null,       `userid` INT not null,       `articleid` INT not null,        primary key (`commentid`)    );    alter table `bbs`.`comment`          add index `comment_article_fk`(`articleid`),         add constraint `comment_article_fk`         foreign key (`articleid`)         references `bbs`.`article`(`articleid`);    alter table `bbs`.`comment`          add index `comment_user_fk`(`userid`),         add constraint `comment_user_fk`         foreign key (`userid`)         references `bbs`.`user`(`userid`);    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`);

2. The project code is as follows:

The main implementation of the Code: Solve the Problem of Chinese garbled characters:

Public class MyFilter implements Filter {private String encoding = null; public void doFilter (ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {encode (encoding); arg2.doFilter (arg0, arg1);} public void init (FilterConfig arg0) throws ServletException {encoding = arg0.getInitParameter ("encoding"); // obtain the encoding} public void destroy () {}} in the configuration file (){}}

Configure in the web. xml file

<! -- Filter Chinese garbled characters --> <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

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.