基于J2EE Web组件技术的课程设计实训项目——《BBS论坛系统》——解决系统中表单重复提交的技术问题
- 格式:pdf
- 大小:171.21 KB
- 文档页数:12
基于J2EE Web组件技术的课程设计实训项目——《BBS论坛系统》——构建系统业务层中的论坛信息管理的业务功能组件(第2/2部分)1.1.1添加与论坛信息功能处理相关的各个业务处理类1、添加与论坛信息功能处理相关的业务处理接口(1)接口的名称为BBSInfoManageInterface,包名称为com.px1987.webbbs.model(2)BBSInfoManageInterface接口的代码示例package com.px1987.webbbs.model;import java.util.*;import com.px1987.webbbs.exception.*;public interface BBSInfoManageInterface{public boolean doSaveBBSInfo(BBSInfoVO oneBBSInfo) throws WebBBSException;public boolean doSaveBBSReplyInfo(BBSReplyInfoVO oneBBSReplyInfo) throws WebBBSException;public boolean doUpdateBBSInfo(BBSInfoVO oneBBSInfoVO) throws WebBBSException;public ArrayList doSeacherBBSInfo(String searchKind,String keyText) throwsWebBBSException;public ArrayList doGetTodayAllBBSInfo() throws WebBBSException;public int doGetTodayAllBBSInfoCount() throws WebBBSException;public ArrayList doGetBBSTitleInfo() throws WebBBSException;public ArrayList doGetBBSTitleInfo(int titleCounte) throws WebBBSException;public ArrayList doGetBBSInfoByTitleID(int bbsTitleID) throws WebBBSException;public BBSInfoVO doGetOneBBSInfoByBBSID(int bbsInfoID) throws WebBBSException;public ArrayList doGetBBSInfoByHits() throws WebBBSException;public ArrayList doGetBBSInfoByHits(int bbsCounte) throws WebBBSException;public int doGetPageTotalBBSInfoCounterByTitleID(int bbsTitleID) throws WebBBSException;public int doGetTotalBBSInfoCounter() throws WebBBSException;public int doGetTotalBBSTitleInfoCounter() throws WebBBSException;public ArrayList doGetPageBBSInfoByTitleID(int bbsTitleID,int firstResult, int maxResults) throws WebBBSException;public BBSTitleVO doGetBBSTitleInfoByTitleID(int bbsTitleID) throws WebBBSException;}2、为BBSInfoManageInterface接口提供实现类BBSInfoManageImple,包名称为com.px1987.webbbs.model3、编程BBSInfoManageImple实现类中相关的功能实现方法package com.px1987.webbbs.model;import java.util.*;import com.px1987.webbbs.exception.WebBBSException;import com.px1987.webbbs.dao.*;import java.sql.*;import com.px1987.webbbs.util.*;public class BBSInfoManageImple implements BBSInfoManageInterface{ BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;public void setBbsInfoManageDAOBean(BBSInfoManageDAOInterface bbsInfoManageDAOBean){this.bbsInfoManageDAOBean = bbsInfoManageDAOBean;}public BBSInfoManageImple() {}public ArrayList doGetBBSInfoByHits() throws WebBBSException{ ArrayList allBBSInfoVOList=null;// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;ArrayList allBBSInfoPOList=null;Iterator allBBSInfoPOItem=null;allBBSInfoVOList=new ArrayList();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();allBBSInfoPOList=bbsInfoManageDAOBean.SelectBBSInfoByBBSHits();allBBSInfoPOItem=allBBSInfoPOList.iterator();while(allBBSInfoPOItem.hasNext()){BBSInfoPO oneBBSInfoPO=(BBSInfoPO)allBBSInfoPOItem.next();BBSInfoVO oneBBSInfoVO=new BBSInfoVO();oneBBSInfoVO.setAuthor(oneBBSInfoPO.getAuthor());oneBBSInfoVO.setTitle(oneBBSInfoPO.getTitle());oneBBSInfoVO.setReplay(oneBBSInfoPO.getReplay());oneBBSInfoVO.setHits(oneBBSInfoPO.getHits());oneBBSInfoVO.setSendInfoTime(oneBBSInfoPO.getSendInfoTime());oneBBSInfoVO.setContent(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getContent()));oneBBSInfoVO.setAbstractText(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getAbstractText()));oneBBSInfoVO.setMailto(oneBBSInfoPO.getMailto());oneBBSInfoVO.setLastUpdateTime(oneBBSInfoPO.getLastUpdateTime());oneBBSInfoVO.setBbsIconID(oneBBSInfoPO.getBbsIconID());oneBBSInfoVO.setBbsTypeID(oneBBSInfoPO.getBbsTypeID());oneBBSInfoVO.setBbsTitleID(oneBBSInfoPO.getBbsTitleID());oneBBSInfoVO.setUserID(oneBBSInfoPO.getUserID());oneBBSInfoVO.setBbsID(oneBBSInfoPO.getId());allBBSInfoVOList.add(oneBBSInfoVO);}return allBBSInfoVOList;}public ArrayList doGetBBSInfoByHits(int bbsCounte) throws WebBBSException{ ArrayList allBBSInfoVOList=null;// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;ArrayList allBBSInfoPOList=null;Iterator allBBSInfoPOItem=null;allBBSInfoVOList=new ArrayList();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();allBBSInfoPOList=bbsInfoManageDAOBean.SelectBBSInfoByBBSHits(bbsCounte);allBBSInfoPOItem=allBBSInfoPOList.iterator();while(allBBSInfoPOItem.hasNext()){BBSInfoPO oneBBSInfoPO=(BBSInfoPO)allBBSInfoPOItem.next();BBSInfoVO oneBBSInfoVO=new BBSInfoVO();oneBBSInfoVO.setAuthor(oneBBSInfoPO.getAuthor());oneBBSInfoVO.setTitle(oneBBSInfoPO.getTitle());oneBBSInfoVO.setReplay(oneBBSInfoPO.getReplay());oneBBSInfoVO.setHits(oneBBSInfoPO.getHits());oneBBSInfoVO.setSendInfoTime(oneBBSInfoPO.getSendInfoTime());oneBBSInfoVO.setContent(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getContent()));oneBBSInfoVO.setAbstractText(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getAbstractText()));oneBBSInfoVO.setMailto(oneBBSInfoPO.getMailto());oneBBSInfoVO.setLastUpdateTime(oneBBSInfoPO.getLastUpdateTime());oneBBSInfoVO.setBbsIconID(oneBBSInfoPO.getBbsIconID());oneBBSInfoVO.setBbsTypeID(oneBBSInfoPO.getBbsTypeID());oneBBSInfoVO.setBbsTitleID(oneBBSInfoPO.getBbsTitleID());oneBBSInfoVO.setUserID(oneBBSInfoPO.getUserID());oneBBSInfoVO.setBbsID(oneBBSInfoPO.getId());allBBSInfoVOList.add(oneBBSInfoVO);}return allBBSInfoVOList;}public ArrayList doGetBBSInfoByTitleID(int bbsTitleID) throws WebBBSException {ArrayList allBBSInfoVOList=null;// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;ArrayList allBBSInfoPOList=null;Iterator allBBSInfoPOItem=null;allBBSInfoVOList=new ArrayList();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple(); allBBSInfoPOList=bbsInfoManageDAOBean.SelectBBSInfoByBBSTitleID(bbsTitleID);allBBSInfoPOItem=allBBSInfoPOList.iterator();while(allBBSInfoPOItem.hasNext()){BBSInfoPO oneBBSInfoPO=(BBSInfoPO)allBBSInfoPOItem.next();BBSInfoVO oneBBSInfoVO=new BBSInfoVO();oneBBSInfoVO.setAuthor(oneBBSInfoPO.getAuthor());oneBBSInfoVO.setTitle(oneBBSInfoPO.getTitle());oneBBSInfoVO.setReplay(oneBBSInfoPO.getReplay());oneBBSInfoVO.setHits(oneBBSInfoPO.getHits());oneBBSInfoVO.setSendInfoTime(oneBBSInfoPO.getSendInfoTime());oneBBSInfoVO.setContent(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getContent()));oneBBSInfoVO.setAbstractText(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getAbstractText()));oneBBSInfoVO.setMailto(oneBBSInfoPO.getMailto());oneBBSInfoVO.setLastUpdateTime(oneBBSInfoPO.getLastUpdateTime());oneBBSInfoVO.setBbsIconID(oneBBSInfoPO.getBbsIconID());oneBBSInfoVO.setBbsTypeID(oneBBSInfoPO.getBbsTypeID());oneBBSInfoVO.setBbsTitleID(oneBBSInfoPO.getBbsTitleID());oneBBSInfoVO.setUserID(oneBBSInfoPO.getUserID());oneBBSInfoVO.setBbsID(oneBBSInfoPO.getId());allBBSInfoVOList.add(oneBBSInfoVO);}return allBBSInfoVOList;}public ArrayList doGetBBSTitleInfo(int titleCounte) throws WebBBSException{ ArrayList allBBSTitleVOList=null;// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;ArrayList allBBSTitlePOList=null;Iterator allBBSTitlePOItem=null;allBBSTitleVOList=new ArrayList();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();allBBSTitlePOList=bbsInfoManageDAOBean.getSomeBbsTitleInfos(titleCounte);allBBSTitlePOItem=allBBSTitlePOList.iterator();while(allBBSTitlePOItem.hasNext()){BBSTitlePO oneBBSTitlePO=(BBSTitlePO)allBBSTitlePOItem.next();BBSTitleVO oneBBSTitleVO=new BBSTitleVO();oneBBSTitleVO.setBbsTitleID(oneBBSTitlePO.getId());oneBBSTitleVO.setBbsTitle(oneBBSTitlePO.getBbsTitle());oneBBSTitleVO.setTitleLeaderName(oneBBSTitlePO.getTitleLeaderName());oneBBSTitleVO.setTotalTopicNumber(oneBBSTitlePO.getTotalTopicNumber());oneBBSTitleVO.setTodayTopicNumber(oneBBSTitlePO.getTodayTopicNumber());oneBBSTitleVO.setLastSendTime(oneBBSTitlePO.getLastSendTime());oneBBSTitleVO.setLastTopicAuthor(oneBBSTitlePO.getLastTopicAuthor());oneBBSTitleVO.setNewTopic(oneBBSTitlePO.getNewTopic());oneBBSTitleVO.setTitleAbstractText(oneBBSTitlePO.getTitleAbstractText());oneBBSTitleVO.setUserID(oneBBSTitlePO.getUserID());allBBSTitleVOList.add(oneBBSTitleVO);}return allBBSTitleVOList;}public ArrayList doGetBBSTitleInfo() throws WebBBSException{ArrayList allBBSTitleVOList=null;// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;ArrayList allBBSTitlePOList=null;Iterator allBBSTitlePOItem=null;allBBSTitleVOList=new ArrayList();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();allBBSTitlePOList=bbsInfoManageDAOBean.getAllBbsTitleInfos();allBBSTitlePOItem=allBBSTitlePOList.iterator();while(allBBSTitlePOItem.hasNext()){BBSTitlePO oneBBSTitlePO=(BBSTitlePO)allBBSTitlePOItem.next();BBSTitleVO oneBBSTitleVO=new BBSTitleVO();oneBBSTitleVO.setBbsTitleID(oneBBSTitlePO.getId());oneBBSTitleVO.setBbsTitle(oneBBSTitlePO.getBbsTitle());oneBBSTitleVO.setTitleLeaderName(oneBBSTitlePO.getTitleLeaderName());oneBBSTitleVO.setTotalTopicNumber(oneBBSTitlePO.getTotalTopicNumber());oneBBSTitleVO.setTodayTopicNumber(oneBBSTitlePO.getTodayTopicNumber());oneBBSTitleVO.setLastSendTime(oneBBSTitlePO.getLastSendTime());oneBBSTitleVO.setLastTopicAuthor(oneBBSTitlePO.getLastTopicAuthor());oneBBSTitleVO.setNewTopic(oneBBSTitlePO.getNewTopic());oneBBSTitleVO.setTitleAbstractText(oneBBSTitlePO.getTitleAbstractText());oneBBSTitleVO.setUserID(oneBBSTitlePO.getUserID());allBBSTitleVOList.add(oneBBSTitleVO);}return allBBSTitleVOList;}public BBSTitleVO doGetBBSTitleInfoByTitleID(int bbsTitleID) throwsWebBBSException{// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;BBSTitleVO oneBBSTitleVO=null;BBSTitlePO oneBBSTitlePO=null;oneBBSTitleVO=new BBSTitleVO();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();oneBBSTitlePO=bbsInfoManageDAOBean.SelectBBSTitleByBBSTitleID(bbsTitleID);oneBBSTitleVO.setBbsTitleID(oneBBSTitlePO.getId());oneBBSTitleVO.setBbsTitle(oneBBSTitlePO.getBbsTitle());oneBBSTitleVO.setTitleLeaderName(oneBBSTitlePO.getTitleLeaderName());oneBBSTitleVO.setTotalTopicNumber(oneBBSTitlePO.getTotalTopicNumber());oneBBSTitleVO.setTodayTopicNumber(oneBBSTitlePO.getTodayTopicNumber());oneBBSTitleVO.setLastSendTime(oneBBSTitlePO.getLastSendTime());oneBBSTitleVO.setLastTopicAuthor(oneBBSTitlePO.getLastTopicAuthor());oneBBSTitleVO.setNewTopic(oneBBSTitlePO.getNewTopic());oneBBSTitleVO.setTitleAbstractText(oneBBSTitlePO.getTitleAbstractText());oneBBSTitleVO.setUserID(oneBBSTitlePO.getUserID());return oneBBSTitleVO;}public BBSInfoVO doGetOneBBSInfoByBBSID(int bbsInfoID)throws WebBBSException {return null;}public ArrayList doGetPageBBSInfoByTitleID(int bbsTitleID, int firstResult, int maxResults) throws WebBBSException {return null;}public int doGetPageTotalBBSInfoCounterByTitleID(int bbsTitleID)throws WebBBSException {return 0;}public int doGetTotalBBSInfoCounter() throws WebBBSException{// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;int bbsInfoTotalCounter=0;// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();bbsInfoTotalCounter=bbsInfoManageDAOBean.getBBSInfoTotalCounter();return bbsInfoTotalCounter;}public int doGetTotalBBSTitleInfoCounter() throws WebBBSException{// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;int bbsTitleInfoTotalCounter=0;// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple(); bbsTitleInfoTotalCounter=bbsInfoManageDAOBean.getBBSTitleInfoTotalCounter();return bbsTitleInfoTotalCounter;}public boolean doSaveBBSInfo(BBSInfoVO oneBBSInfoVO) throws WebBBSException{ // BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;boolean OKOrNot=false;BBSInfoPO oneBBSInfoPO=new BBSInfoPO();String bbsAuthor=oneBBSInfoVO.getAuthor();oneBBSInfoPO.setId(oneBBSInfoVO.getBbsID());oneBBSInfoPO.setAuthor(bbsAuthor);oneBBSInfoPO.setTitle(oneBBSInfoVO.getTitle());oneBBSInfoPO.setReplay(oneBBSInfoVO.getReplay());oneBBSInfoPO.setHits(oneBBSInfoVO.getHits());oneBBSInfoPO.setSendInfoTime(oneBBSInfoVO.getSendInfoTime());oneBBSInfoPO.setContent(oneBBSInfoVO.getContent());oneBBSInfoPO.setMailto(oneBBSInfoVO.getMailto());oneBBSInfoPO.setAbstractText(oneBBSInfoVO.getAbstractText());oneBBSInfoPO.setLastUpdateTime(oneBBSInfoVO.getLastUpdateTime());oneBBSInfoPO.setBbsIconID(oneBBSInfoVO.getBbsIconID());oneBBSInfoPO.setBbsTypeID(oneBBSInfoVO.getBbsTypeID());int bbsTitleID=oneBBSInfoVO.getBbsTitleID();oneBBSInfoPO.setBbsTitleID(bbsTitleID);oneBBSInfoPO.setUserID(oneBBSInfoVO.getUserID());// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();OKOrNot=bbsInfoManageDAOBean.InsertBBSInfo(oneBBSInfoPO);// 下面的代码是根据bbsTitleID来更新BBTitle中的 totalTopicNumber计数bbsInfoManageDAOBean.UpdateBBTitleCounterByBbsTitleID(bbsTitleID,bbsAuthor);return OKOrNot;}public boolean doSaveBBSReplyInfo(BBSReplyInfoVO oneBBSReplyInfo) throws WebBBSException {return false;}public ArrayList doSeacherBBSInfo(String searchKind, String keyText) throws WebBBSException {ArrayList allSearchResultBBSInfoPOArrayList=null;ArrayList allSearchResultBBSInfoVOArrayList=null;BBSInfoPO oneBBSInfoPO=null;BBSInfoVO oneBBSInfoVO=null;String hqlSelect="";// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;allSearchResultBBSInfoVOArrayList=new ArrayList();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();switch(Integer.parseInt(searchKind)){case 1: // 留言作者allSearchResultBBSInfoPOArrayList=bbsInfoManageDAOBean.SelectBBSInfoByBBSAuthor(keyText);break;case 2: // 留言标题allSearchResultBBSInfoPOArrayList=bbsInfoManageDAOBean.SelectBBSInfoByBBSTitle(keyText);break;case 3: // 留言时间allSearchResultBBSInfoPOArrayList=bbsInfoManageDAOBean.SelectBBSInfoByBBSSendInfoTime(keyText);break;}Iterator allBBSInfoPOIteratorItem=allSearchResultBBSInfoPOArrayList.iterator();while(allBBSInfoPOIteratorItem.hasNext()){//下靟的代码实现将PO(BBSInfo)--->VO(BBSInfoVO)oneBBSInfoPO = (BBSInfoPO) allBBSInfoPOIteratorItem.next();oneBBSInfoVO = new BBSInfoVO();oneBBSInfoVO.setAuthor(oneBBSInfoPO.getAuthor());oneBBSInfoVO.setTitle(oneBBSInfoPO.getTitle());oneBBSInfoVO.setReplay(oneBBSInfoPO.getReplay());oneBBSInfoVO.setHits(oneBBSInfoPO.getHits());oneBBSInfoVO.setSendInfoTime(oneBBSInfoPO.getSendInfoTime());oneBBSInfoVO.setMailto(oneBBSInfoPO.getMailto());oneBBSInfoVO.setContent(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getContent())); oneBBSInfoVO.setAbstractText(TransferSpecialCharToHTMLEntity.FilterCharToHTMLEntity(oneBBSInfoPO.getAbstractText())); oneBBSInfoVO.setLastUpdateTime(oneBBSInfoPO.getLastUpdateTime());oneBBSInfoVO.setBbsIconID(oneBBSInfoPO.getBbsIconID());oneBBSInfoVO.setBbsTypeID(oneBBSInfoPO.getBbsTypeID());oneBBSInfoVO.setBbsTitleID(oneBBSInfoPO.getBbsTitleID());oneBBSInfoVO.setUserID(oneBBSInfoPO.getUserID());oneBBSInfoVO.setBbsID(oneBBSInfoPO.getId().intValue());allSearchResultBBSInfoVOArrayList.add(oneBBSInfoVO);}//此时在ArrayList中将包含有BBSInfoVO类型的对象雃合return allSearchResultBBSInfoVOArrayList;}public ArrayList doGetTodayAllBBSInfo() throws WebBBSException{ String keyText = "";ArrayList newBBSInfoList = null;java.util.Date rightNow = new java.util.Date();keyText = (1900 + rightNow.getYear()) + "-" + (rightNow.getMonth() + 1) +"-" + rightNow.getDate();String searchKind="3"; //"3"代表按照时间搜索newBBSInfoList=doSeacherBBSInfo(searchKind, keyText);return newBBSInfoList;}public int doGetTodayAllBBSInfoCount() throws WebBBSException{int totalBBSCounter=0;// BBSInfoManageDAOInterface bbsInfoManageDAOBean=null;String todayDate = "";java.util.Date rightNow = new java.util.Date();todayDate = (1900 + rightNow.getYear()) + "-" + (rightNow.getMonth() + 1)+"-" + rightNow.getDate();// bbsInfoManageDAOBean=new BBSInfoManageDAOJDBCImple();totalBBSCounter=bbsInfoManageDAOBean.getBBSInfoCounterBySendTime(todayDate);return totalBBSCounter;}public boolean doUpdateBBSInfo(BBSInfoVO oneBBSInfoVO)throws WebBBSException {return false;}}。
基于J2EE Struts框架的课程设计实训项目——《BBS论坛系统》——实现用户身份验证表单中的图形验证码功能1.1.1实现图形验证码功能1、添加一个实现验证码功能的JavaBean组件类(1)类名称为VerifyCodeBean,包名称为com.px1987.webbbs.util(2)编程该JavaBeanpackage com.px1987.webbbs.util;import java.awt.*;import java.awt.image.BufferedImage;import java.util.*;public class VerifyCodeBean{private Random random ;private int width;private int height;private String VerifyCode = ""; //存储随机产生的认证码(6位数字或者字母) public VerifyCodeBean(){this.width = 90;this.height = 20;random = new Random(); //生成随机类}public int getHeight(){return height;}public void setHeight(int height){this.height = height;}public Random getRandom(){return random;}public void setRandom(Random random){this.random = random;}public String getVerifyCode(){return VerifyCode;}public void setVerifyCode(String verifyCode){VerifyCode = verifyCode;}public int getWidth(){return width;}public void setWidth(int width){this.width = width;}private Color getRandomColor(int foregroundColor,int backgroundColor){ //给定范围获得随机颜色if(foregroundColor > 255){foregroundColor = 255;}if(backgroundColor > 255){backgroundColor = 255;}int r = foregroundColor +random.nextInt(backgroundColor-foregroundColor);int g = foregroundColor +random.nextInt(backgroundColor-foregroundColor);int b = foregroundColor +random.nextInt(backgroundColor-foregroundColor);return new Color(r,g,b);}public BufferedImage getCreateVerifyImage(){//创建一个BufferedImage绘制你的动态图像BufferedImage image =new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);/**创建完一个BufferedImage后,你需要得到图形环境进行绘制,一个Graphics或者Graphics2D对象*/Graphics2D g2d = image.createGraphics();Graphics g = (Graphics)g2d;g.setColor(this.getRandomColor(180, 250));/*生成有6个随机数字和杂乱背景的图片,数字和背景颜色会改变,服务器端刷新(用history.go(-1)也会变)*/g.fillRect(0, 0, width, height);g.setFont(new Font("Times New Roman",Font.PLAIN,18));g.setColor(Color.BLUE);g.drawRect(0,0,width-1,height-1);//画随机线g.setColor(this.getRandomColor(160,200));/*随机产生155条干扰线,使图象中的认证码不易被其它程序探测到*/for(int i = 0 ; i < 150 ; i++){int x = random.nextInt(width);int y = random.nextInt(height);int x1 = random.nextInt(12);int y1 = random.nextInt(12);g.drawLine(x, y, x+x1, y+y1);}for(int i = 0 ; i < 6 ; i++){String[] str = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v","w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H","I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T","U", "V", "W", "X", "Y", "Z","1","2","3","4","5","6","7","8","9" };String randomStr = str[random.nextInt(str.length-1)];//String randomStr = String.valueOf(random.nextInt(10));VerifyCode+=randomStr; // 取随机产生的认证码(4位数字)g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));/*将认证码显示到图象中*/g.drawString(randomStr,13*i+6,16);}/*上面为绘制图像内容,对图形环境绘制就会画到BufferedImage。
J2EE课程设计及项目实训教学中的项目需求分析——《BBS论坛系统》的需求说明1.1.1BBS论坛需求说明1、该网站建设包含以下子系统2、用户脚色划分(1)普通用户普通用户以游客身份登录,只具有察看帖子的功能,不能留言。
(2)注册用户具备普通用户所有的能力。
并且是已经注册了的用户,可以登录、修改个人信息,并且可以发表留言。
(3)管理员管理员登录以后可以对论坛系统进行管理,包括论坛的基本信息、用户设置,还可以修改管理员密码。
3、前台服务系统修改帖子(from Use Case View)3.1、注册主要是指除管理员以外的用户角色,在网上在线填写一些会员的注册信息。
注册后即可成为BBS论坛会员。
会员注册信息如下:注册确认用户通过网上在线注册后,由系统管理员收集相应的资料,核实后,进行用户注册确认,确认后用户成为会员正式生效,可以享受网站提供的各种服务。
3.2、登录用户输入登录信息,如用户名、密码、验证码,以会员的身份进入本论坛。
或者以游客身份登录,不需要输入任何信息即可。
3.3、修改信息会员登录成功后,可以修改自己的信息,如密码等。
3.4、留言管理会员有发布,回复帖子的功能。
但只有注册并且登录成功的会员才具有这一功能。
会员可以修改自己的留言和查看、删除、自己的帖子。
4、后台管理系统(1)各个子模块(2)系统管理员及其职责5、后台管理系统系统管理员登陆: 系统管理员提交用户名和密码,系统验证用户名和密码的合法性,系统显示系统管理员管理页面(包含管理员的信息)6、论坛基本信息管理:对网站参数、通行证设置、COOKIE设置、公告设置进行管理。
7、管理用户:管理员设置一些用户的信息,如:用户权限、封锁用户、用户级别设置等等。
8、发帖设置:对用户的帖子设置、上传文件设置、全文检索设置、缓存设置进行管理。
基于J2EE Web组件技术的课程设计实训项目——《BBS论坛系统》——构建系统持久层中的用户信息管理的DAO组件1.1.1构建系统持久层中的用户信息管理的DAO组件1、添加封装用户信息的实体基类UserInfoBasePO(1)类名称为UserInfoBasePO,包名称为com.px1987.webbbs.dao(2)在该UserInfoBasePO类中添加下面的个属性private Integer id;private String userName;private String userPassWord;private int userType;private String aliaoName;private String passWordAsk;private String registerTime;private String passWordAnswer;private String userMail;private int userSex;private String userBirthDay;private String userComeFrom;private String userResume;(3)为上面的各个属性提供get/set方法(4)UserInfoBasePO类的代码示例package com.px1987.webbbs.dao;public class UserInfoBasePO{private Integer id;private String userName;private String userPassWord;private int userType;private String passWordAsk;private String userImage;private String registerTime;private String passWordAnswer;private String userMail;private int userSex;private String userBirthDay;private String userComeFrom;private String userResume;public UserInfoBasePO(){}public String getAliaoName() {return aliaoName;}public void setAliaoName(String aliaoName) { this.aliaoName = aliaoName;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getPassWordAnswer() {return passWordAnswer;}public void setPassWordAnswer(String passWordAnswer) { this.passWordAnswer = passWordAnswer;}public String getPassWordAsk() {return passWordAsk;}public void setPassWordAsk(String passWordAsk) { this.passWordAsk = passWordAsk;}public String getRegisterTime() {return registerTime;}public void setRegisterTime(String registerTime) { this.registerTime = registerTime;}public String getUserBirthDay() {return userBirthDay;}public void setUserBirthDay(String userBirthDay) { erBirthDay = userBirthDay;}public String getUserComeFrom() {return userComeFrom;}public void setUserComeFrom(String userComeFrom) { erComeFrom = userComeFrom;}public String getUserImage() {return userImage;}public void setUserImage(String userImage) { erImage = userImage;}public String getUserMail() {return userMail;}public void setUserMail(String userMail) { erMail = userMail;}public String getUserName() {return userName;}public void setUserName(String userName) { erName = userName;}public String getUserPassWord() {return userPassWord;}public void setUserPassWord(String userPassWord) { erPassWord = userPassWord;}public String getUserResume() {return userResume;}public void setUserResume(String userResume) { erResume = userResume;}public int getUserSex() {return userSex;}public void setUserSex(int userSex) {erSex = userSex;}public int getUserType() {return userType;}public void setUserType(int userType) {erType = userType;}public boolean equals(Object other){if (this == other){return true;}if (! (other instanceof UserInfoBasePO)){return false;}return true;}}2、添加封装用户信息的实体类UserInfoPO类(1)类名称为UserInfoPO,包名称为com.px1987.webbbs.dao,并且从UserInfoBasePO 类来继承(2)在该UserInfoPO类中添加下面的个属性private Map contactMethod = new HashMap();private String userSign;private int emailVisible;private int acceptAdvise;(3)为上面的各个属性提供get/set方法(4)最后为下面的状态package com.px1987.webbbs.dao;import java.util.*;public class UserInfoPO extends UserInfoBasePO { private Map contactMethod = new HashMap();private String userSign;private int emailVisible;private int acceptAdvise;public UserInfoPO(){}public int getAcceptAdvise() {return acceptAdvise;}public void setAcceptAdvise(int acceptAdvise) { this.acceptAdvise = acceptAdvise;}public Map getContactMethod() {return contactMethod;}public void setContactMethod(Map contactMethod) {this.contactMethod = contactMethod;}public int getEmailVisible() {return emailVisible;}public void setEmailVisible(int emailVisible) {this.emailVisible = emailVisible;}public String getUserSign() {return userSign;}public void setUserSign(String userSign) {erSign = userSign;}public boolean equals(Object other){if (this == other) {return true;}if (! (other instanceof UserInfoPO)){return false;}return true;}public void addOneContactMethod(String oneContactMethodKey,String oneContactMethodValue) { //该方法为“帮助方法”contactMethod.put(oneContactMethodKey,oneContactMethodValue);}public String getOneContactMethod(String oneContactMethodKey) { //该方法为“帮助方法”return (String)contactMethod.get(oneContactMethodKey);}private Set bbsInfos = new HashSet(); //在“一”端(UserInfo)的PO类中增加一个“多”端(BBSInfo)的集合对象的属性public Set getBbsInfos() {return bbsInfos;}public void setBbsInfos(Set bbsInfos) {this.bbsInfos = bbsInfos;}public ArrayList getBBSInfoSByUser(){//利用该方法可以获得该用户所发表的BBS信息ArrayList allBBSInfosByOneUser=null;allBBSInfosByOneUser=new ArrayList();java.util.Iterator allBBSInfoItemIterator = getBbsInfos().iterator();while(allBBSInfoItemIterator.hasNext()){BBSInfoPO oneBBSInfo=(BBSInfoPO)allBBSInfoItemIterator.next();allBBSInfosByOneUser.add(oneBBSInfo);}return allBBSInfosByOneUser;}}3、添加封装论坛系统中系统管理员信息的实体AdminUserInfoPO类(1)类名称为AdminUserInfoPO,包名称为com.px1987.webbbs.dao,并且从UserInfoBasePO类来继承(2)在该AdminUserInfoPO类中添加下面的个属性private String workUnit;private String studyHistory;private String studySchool;private String idCardNo;(3)为上面的各个属性提供get/set方法(4)最后为下面的状态package com.px1987.webbbs.dao;public class AdminUserInfoPO extends UserInfoBasePO{ private String workUnit;private String studyHistory;private String studySchool;private String idCardNo;public AdminUserInfoPO(){}public String getIdCardNo() {return idCardNo;}public void setIdCardNo(String idCardNo) {this.idCardNo = idCardNo;}public String getStudyHistory() {return studyHistory;}public void setStudyHistory(String studyHistory) { this.studyHistory = studyHistory;}public String getStudySchool() {return studySchool;}public void setStudySchool(String studySchool) { this.studySchool = studySchool;}public String getWorkUnit() {return workUnit;}public void setWorkUnit(String workUnit) {this.workUnit = workUnit;}public boolean equals(Object other){if (this == other){return true;}if (! (other instanceof AdminUserInfoPO)){return false;}return true;}}4、添加对用户信息进行管理的DAO组件的接口(1)接口名称为UserManageDAOInterface,包名称为com.px1987.webbbs.dao(2)设计UserManageDAOInterface接口中的相关功能方法package com.px1987.webbbs.dao;import java.util.*;import com.px1987.webbbs.dao.*;import com.px1987.webbbs.exception.WebBBSException;public interface UserManageDAOInterface{// 下面的方法是针对UserInfoBasePO类的public ArrayList selectAllBaseUserInfo() throws WebBBSException;public ArrayList selectSomeBaseUserInfo(String HQLSelect) throws WebBBSException;// 下面的方法是针对UserInfoPO类的public ArrayList selectAllUserInfo() throws WebBBSException;public ArrayList selectSomeUserInfo(String HQLSelect) throws WebBBSException;public UserInfoPO selectOneUserInfo(String registerUserID) throws WebBBSException;public List selectUserSomePropertyInfo(String HQLSelect) throws WebBBSException;public UserInfoPO SelectOneUserInfoData(String userName, String userPassWord) throws WebBBSException;public boolean insertOneUserInfo(UserInfoPO oneRegisterUserInfo) throws WebBBSException;public boolean updateOneUserInfo(UserInfoPO oneUpdatedRegisterUserInfo) throws WebBBSException;public boolean updateOneUserPassWord(String newPassWord, String registerUserId) throws WebBBSException;public boolean deleteOneUserInfo(String registerUserID) throws WebBBSException;public boolean BatchDeleteUserInfo(ArrayList deletedUserIDs) throws WebBBSException;// 下面的方法是针对AdminUserInfoPO类的public ArrayList selectAllAdminUserInfo() throws WebBBSException;public ArrayList selectSomeAdminUserInfo(String HQLSelect) throws WebBBSException;public AdminUserInfoPO selectOneAdminUserInfo(String adminUserID) throws WebBBSException;public AdminUserInfoPO SelectOneAdminUserInfoData(String userName, String userPassWord) throws WebBBSException;public boolean insertOneAdminUserInfo(AdminUserInfoPO oneAdminUserInfo) throws WebBBSException;public boolean updateOneAdminUserInfo(AdminUserInfoPO oneUpdatedAdminUserInfo) throws WebBBSException;public boolean deleteOneAdminUserInfo(String adminUserID) throws WebBBSException;public boolean BatchDeleteAdminUserInfo(ArrayList deletedUserIDs) throws WebBBSException;}3、添加DAO的接口UserManageDAOInterface的实现类(1)类名称为UserManageDAOJDBCImple,包名称为com.px1987.webbbs.dao(2)编程该实现类package com.px1987.webbbs.dao;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.Map;import com.px1987.webbbs.dao.ConnectDBBean;import com.px1987.webbbs.dao.ConnectDBInterface;import erInfoPO;import com.px1987.webbbs.exception.WebBBSException;import java.sql.*;public class UserManageDAOJDBCImple implements UserManageDAOInterface{ private java.sql.Connection con=null;ConnectDBInterface connectDBBean=null;public UserManageDAOJDBCImple() throws WebBBSException{connectDBBean=new ConnectDBBean();}public boolean BatchDeleteUserInfo(ArrayList deletedUserIDs) throws WebBBSException{return false;}public boolean DeleteOneUserInfo(int deletedUserID) throws WebBBSException{ return false;}public boolean InsertOneUserInfo(UserInfoPO oneUserInfoPO) throws WebBBSException{return false;}public ArrayList SelectAllUserInfoData() throws WebBBSException{ return null;}public UserInfoPO SelectOneUserInfoData(String userName, String userPassWord) throws WebBBSException{ResultSet rs=null;UserInfoPO oneUserInfo=null;String select_SqlStatement=null;select_SqlStatement="select * from userInfo where userName='"+ userName+"' and userPassWord='"+userPassWord+"'";con=connectDBBean.getConnection();try{java.sql.PreparedStatement pstmt =con.prepareStatement(select_SqlStatement,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);rs = pstmt.executeQuery();if(rs.next()){oneUserInfo=new UserInfoPO(); //目前只转换下面的几个属性oneUserInfo.setUserName(rs.getString("userName"));oneUserInfo.setUserPassWord(rs.getString("userPassWord"));}else{oneUserInfo=null;}}catch(SQLException e){throw new WebBBSException("在查询数据库表时出现错误!,异常的详细内容为:"+e.getMessage());}return oneUserInfo;}public ArrayList SelectSomeUserInfoData(Map whereMap) throws WebBBSException{ return null;}public boolean UpdateOneUserInfo(UserInfoPO oneUserInfoPO) throws WebBBSException {return false;}}4、添加实现系统数据库连接组件的接口(1)名称为ConnectDBInterface,包名称为com.px1987.webbbs.dao(2)设计ConnectDBInterface接口中的相关功能方法package com.px1987.webbbs.dao;import java.sql.Connection;public interface ConnectDBInterface {public Connection getConnection();public void closeDBCon();}5、为ConnectDBInterface接口提供实现类(1)类名称为ConnectDBBean,包名称为com.px1987.webbbs.dao(2)编程该实现类package com.px1987.webbbs.dao;import java.sql.*;import com.px1987.webbbs.dao.ConnectDBInterface;import com.px1987.webbbs.exception.*;public class ConnectDBBean implements ConnectDBInterface{String JDBC_JTDS_MSSqlServer_DBDriver= "net.sourceforge.jtds.jdbc.Driver";String JDBC_MSSqlServer_URL ="jdbc:jtds:sqlserver://127.0.0.1:1433/BBSDataBase";private java.sql.Connection con = null;public ConnectDBBean() throws WebBBSException {try{Class.forName(JDBC_JTDS_MSSqlServer_DBDriver);}catch (ng.ClassNotFoundException e){// System.out.println("不能正确地加载JDBC驱动程序");throw new WebBBSException("不能正确地加载JDBC驱动程序");}try{con =DriverManager.getConnection(JDBC_MSSqlServer_URL, "sa", "1234");}catch (java.sql.SQLException e){throw new WebBBSException("不能正确地连接数据库并且出现SQLException");}catch (NullPointerException e){throw new WebBBSException("不能正确地连接数据库并且出现NullPointerException");}}public void closeDBCon() throws WebBBSException{try{con.close();}catch (SQLException e){throw new WebBBSException("不能正确地关闭数据库连接,异常的详细内容为:"+e.getMessage());}}public Connection getConnection() throws WebBBSException{if (con == null){throw new WebBBSException("在ConnectDBBean类中的getConnection方法中con对象为空");}return this.con;}}1.1.2对相关的DAO功能组件进行测试1、添加JDBC驱动程序2、部署并执行本Web应用系统3、启动服务器并执行本Web应用(1)输入http://127.0.0.1:8080/WebBBS/index.jsp(2)输入用户名称。
基于J2EE Web组件技术的课程设计实训项目——《BBS论坛系统》——设置Web应用中的缺省的首页面1.1.1设置Web应用中的缺省的首页面1、设计系统的缺省首页(1)设计两个文件index.html、index.htm其内容都相同。
注意下面的黑体的内容,实际跳转到系统中的真正的首页中。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><meta http-equiv="refresh" content="0;url='/WebBBS/pageForwordAction?action=showIndexContent'"><meta name="keywords" content="BBS论坛"><meta name="description" content="中科院计算所培训中心成立于1987年,已经有20年培训经历。
培训中心从普及与发展全国IT技术人才的迫切需要出发,以建立中国最优秀的专业培训机构为目标,借鉴世界著名培训企业的成功办学经验,积极致力于国民经济各个领域的建设"><title>中科院计算所培训中心BBS论坛</title></head><body style="font-family: 宋体; font-size: 9pt"><p>正在加载主页面,请等待....<br></p></body></html>(2)再设计另一个index.jsp文件其内容与前面的文件相同,但多了一个<%@ page contentType="text/html;charset=gb2312" %>指令。
基于J2EE Struts框架的课程设计实训项目——《BBS论坛系统》——构建系统数据库连接组件及对应的单元测试用例(第2/4部分)1.1.1对前面的ConnectDBBean组件进行单元测试(JUnit Test)1、单元测试(1)单元测试有关的概念(2)为什么要应用它(3)如何应用它2、添加一个测试项目----测试项目和被测试项目应该分离!(1)添加一个Java测试项目(2)项目的名称为TestWebBBS(3)最后为下面的状态3、添加对应用项目的引用4、添加测试用例(TestCase)类(测试类)(1)添加测试用例:什么是测试用例?编程要点?(2)添加Junit的系统包(3)设置测试用例类测试用例类名称为TestConnectDBBean类,包名称为com.px1987.webbbs.daotest,被测试的目标程序类选择为com.px1987.webbbs.dao.ConnectDBBean。
(4)选择被测试的方法4、编程该测试用例类(1)类的代码package com.px1987.webbbs.daotest;import junit.framework.TestCase;import com.px1987.webbbs.config.ClassNameConfig;import com.px1987.webbbs.dao.*;import java.sql.*;import com.px1987.webbbs.exception.*;import com.px1987.webbbs.util.*;public class TestConnectDBBean extends TestCase {ConnectDBInterface connectDBBean=null;String connectDBBeanClassName=null;protected void setUp() throws Exception {super.setUp();connectDBBeanClassName=ClassNameConfig.getProperty("connectDBBean.className");connectDBBean=ConnectDBFactory.newConnectDBBean(connectDBBeanClassName);}protected void tearDown() throws Exception {connectDBBean=null;super.tearDown();}public void testCloseDBCon() throws WebBBSException {connectDBBean.closeDBCon();Connection returnDBCon=connectDBBean.getConnection();this.assertNull(returnDBCon); //断言}public void testGetConnection() throws WebBBSException {Connection returnDBCon=connectDBBean.getConnection();this.assertNotNull(returnDBCon); //断言}}注意:也可以采用的是JUnit4.0系统库,现在改变为“Java标注”的方式实现---其中的@Before、@After和@Test等符号。
基于J2EE Web组件技术的课程设计实训项目——《BBS论坛系统》——解决系统中表单重复提交的技术问题1.1.1解决系统中表单重复提交的技术问题1、关于对用户信息管理中所可能会出现的表单重复提交的问题(1)表单重复提交的问题由于本系统中的各个功能完成后都采用Forward跳转而不是Redirect的形式转到目标页面中,所以当用户完成该请求后,按"F5"键刷新页面时,就会重新提交上次的请求,这样经常会导致系统出错。
(2)解决的基本方法在某个功能页面被加载时(一般为习惯信息或者添加信息的功能页面-----如用户注册或者修改等),将产生一个GUID(Globally Unique Identifier,全局唯一标识符)值的隐藏输入框(本系统中采用时间值):<%java.util.Date nowDate=new java.util.Date();String nowDateString=new Long(nowDate.getTime()).toString();session.setAttribute("tokenTime",nowDateString);%><input type="hidden" name="tokenTime" value="<%=nowDateString%>">同时,将该GUID放到会话(session)中(请见上面的代码);在控制层程序中执行该功能请求之前,首先将会话中所保存的GUID与请求的提交的GUID相互比较,如果两者相同,则将会话中的GUID删除并正常往下执行,否则提示重复提交的错误信息。
public void checkRepeatFormSubmit(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{ boolean OkOrNot=true;HttpSession session=null;/** 下面的代码是识别是否为重复提交请求*/session=request.getSession();String tokenTimeInForm=request.getParameter("tokenTime");String tokenTimeInSession=(String)session.getAttribute("tokenTime");OkOrNot=tokenTimeInSession.equals(tokenTimeInForm);if(!OkOrNot){request.setAttribute("errorText", "您已经产生了注册提交行为,不能再重复进行提交行为!");RequestDispatcheroneRequestDispatcher=request.getRequestDispatcher("/errorDeal/showWebAppError. jsp");oneRequestDispatcher.forward(request, response);return;}session.setAttribute("tokenTime",""); //删除会话中的token的值}1.1.2在项目中实现系统中的异常处理技术1、添加我们自定义的异常类型(1)类名称为WebBBSException,包名称为com.px1987.webbbs.exception,基类为ng.Exception类(2)代码如下package com.px1987.webbbs.exception;public class WebBBSException extends Exception {public WebBBSException(){}public WebBBSException(String message) {super(message);}public WebBBSException(Throwable cause) {super(cause);}public WebBBSException(String message, Throwable cause) { super(message, cause);}}1.1.3在项目中实现应用MD5加密的JavaBean组件1、MD5加密的JavaBean组件(1)类名称为MD5JavaBean,包名称为com.px1987.webbbs.util(2)编程该JavaBean组件package com.px1987.webbbs.util;import ng.reflect.*;public class MD5JavaBean{public MD5JavaBean() {keyBeanInit();}static final int S11 = 7;static final int S12 = 12;static final int S13 = 17;static final int S14 = 22;static final int S21 = 5;static final int S22 = 9;static final int S23 = 14;static final int S24 = 20;static final int S31 = 4;static final int S32 = 11;static final int S33 = 16;static final int S34 = 23;static final int S41 = 6;static final int S42 = 10;static final int S43 = 15;static final int S44 = 21;static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };private long[] state = new long[4]; // state (ABCD)private long[] count = new long[2]; // number of bits, modulo 2^64 (lsb first) private byte[] buffer = new byte[64]; // input bufferpublic String digestHexStr;private byte[] digest = new byte[16];public String getkeyBeanofStr(String inbuf) {keyBeanInit();keyBeanUpdate(inbuf.getBytes(), inbuf.length());keyBeanFinal();digestHexStr = "";for (int i = 0; i < 16; i++) {digestHexStr += byteHEX(digest[i]);}return digestHexStr;}private void keyBeanInit() {count[0] = 0L;count[1] = 0L;state[0] = 0x67452301L;state[1] = 0xefcdab89L;state[2] = 0x98badcfeL;state[3] = 0x10325476L;return;}private long F(long x, long y, long z) {return (x & y) | ((~x) & z);}private long G(long x, long y, long z) {return (x & z) | (y & (~z));}private long H(long x, long y, long z) {return x ^ y ^ z;}private long I(long x, long y, long z) {return y ^ (x | (~z));}private long FF(long a, long b, long c, long d, long x, long s, long ac) {a += F (b, c, d) + x + ac;a = ((int) a << s) | ((int) a >>> (32 - s));a += b;return a;}private long GG(long a, long b, long c, long d, long x, long s, long ac) {a += G (b, c, d) + x + ac;a = ((int) a << s) | ((int) a >>> (32 - s));a += b;return a;}private long HH(long a, long b, long c, long d, long x, long s, long ac) {a += H (b, c, d) + x + ac;a = ((int) a << s) | ((int) a >>> (32 - s));a += b;return a;}private long II(long a, long b, long c, long d, long x, long s, long ac) {a += I (b, c, d) + x + ac;a = ((int) a << s) | ((int) a >>> (32 - s));a += b;return a;}private void keyBeanUpdate(byte[] inbuf, int inputLen) {int i, index, partLen;byte[] block = new byte[64];index = (int)(count[0] >>> 3) & 0x3F;// /* Update number of bits */if ((count[0] += (inputLen << 3)) < (inputLen << 3))count[1]++;count[1] += (inputLen >>> 29);partLen = 64 - index;// Transform as many times as possible.if (inputLen >= partLen) {keyBeanMemcpy(buffer, inbuf, index, 0, partLen); keyBeanTransform(buffer);for (i = partLen; i + 63 < inputLen; i += 64) { keyBeanMemcpy(block, inbuf, 0, i, 64); keyBeanTransform (block);}index = 0;} elsei = 0;///* Buffer remaining input */keyBeanMemcpy(buffer, inbuf, index, i, inputLen - i);}private void keyBeanFinal () {byte[] bits = new byte[8];int index, padLen;///* Save number of bits */Encode (bits, count, 8);///* Pad out to 56 mod 64.index = (int)(count[0] >>> 3) & 0x3f;padLen = (index < 56) ? (56 - index) : (120 - index);keyBeanUpdate (PADDING, padLen);///* Append length (before padding) */keyBeanUpdate(bits, 8);///* Store state in digest */Encode (digest, state, 16);}private void keyBeanMemcpy (byte[] output, byte[] input,int outpos, int inpos, int len){int i;for (i = 0; i < len; i++)output[outpos + i] = input[inpos + i];}private void keyBeanTransform (byte block[]) {long a = state[0], b = state[1], c = state[2], d = state[3]; long[] x = new long[16];Decode (x, block, 64);/* Round 1 */a = FF (a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */d = FF (d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */c = FF (c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */b = FF (b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */a = FF (a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */d = FF (d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */c = FF (c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */b = FF (b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */a = FF (a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */d = FF (d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */c = FF (c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */b = FF (b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */a = FF (a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */d = FF (d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */c = FF (c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */b = FF (b, c, d, a, x[15], S14, 0x49b40821L); /* 16 *//* Round 2 */a = GG (a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */d = GG (d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */c = GG (c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */b = GG (b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */a = GG (a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */d = GG (d, a, b, c, x[10], S22, 0x2441453L); /* 22 */c = GG (c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */ b = GG (b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */ a = GG (a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */d = GG (d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */ c = GG (c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */ b = GG (b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */ a = GG (a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */ d = GG (d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */ c = GG (c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */ b = GG (b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */ /* Round 3 */a = HH (a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */ d = HH (d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */ c = HH (c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */b = HH (b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */ a = HH (a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */ d = HH (d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */c = HH (c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */ b = HH (b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */ a = HH (a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */d = HH (d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */ c = HH (c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */ b = HH (b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */ a = HH (a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */ d = HH (d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */ c = HH (c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */ b = HH (b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */ /* Round 4 */a = II (a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */ d = II (d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */c = II (c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */b = II (b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */a = II (a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */d = II (d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */c = II (c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */b = II (b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */a = II (a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */d = II (d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */c = II (c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */b = II (b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */a = II (a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */d = II (d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */c = II (c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */b = II (b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */state[0] += a;state[1] += b;state[2] += c;state[3] += d;}private void Encode (byte[] output, long[] input, int len) {int i, j;for (i = 0, j = 0; j < len; i++, j += 4) {output[j] = (byte)(input[i] & 0xffL);output[j + 1] = (byte)((input[i] >>> 8) & 0xffL); output[j + 2] = (byte)((input[i] >>> 16) & 0xffL); output[j + 3] = (byte)((input[i] >>> 24) & 0xffL); }}private void Decode (long[] output, byte[] input, int len) {int i, j;for (i = 0, j = 0; j < len; i++, j += 4)output[i] = b2iu(input[j]) |(b2iu(input[j + 1]) << 8) |(b2iu(input[j + 2]) << 16) |(b2iu(input[j + 3]) << 24);return;}public static long b2iu(byte b) {return b < 0 ? b & 0x7F + 128 : b;}public static String byteHEX(byte ib) {char[] Digit = { '0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F' };char [] ob = new char[2];ob[0] = Digit[(ib >>> 4) & 0X0F];ob[1] = Digit[ib & 0X0F];String s = new String(ob);return s;}}。