码迷,mamicode.com
首页 > Web开发 > 详细

JSP-Servlet实现网上BBS项目小案例

时间:2015-04-07 13:52:03      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:数据库   jsp   bbs   

项目功能:实现一般bbs论坛项目的功能,发表说说 其他好友可以评论

一、数据库的创建:
技术分享
sql语句如下:

    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`);

二、项目代码如下:
技术分享

代码的主要实现:解决中文乱码的问题:

public class MyFilter implements Filter {

    private String encoding=null;  

    public void doFilter(ServletRequest arg0, ServletResponse arg1,
            FilterChain arg2) throws IOException, ServletException {
        arg0.setCharacterEncoding(encoding);   
        arg2.doFilter(arg0, arg1);  
    }

    public void init(FilterConfig arg0) throws ServletException {
        encoding = arg0.getInitParameter("encoding"); //获得配置文件中的encoding
    }

    public void destroy() {

    }
}

在web.xml文件中配置

<!-- 过滤中文乱码的问题 -->
    <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>

全部代码在这里:http://download.csdn.net/detail/u010870518/8570147

JSP-Servlet实现网上BBS项目小案例

标签:数据库   jsp   bbs   

原文地址:http://blog.csdn.net/xlgen157387/article/details/44918915

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!