资源预览内容
第1页 / 共43页
第2页 / 共43页
第3页 / 共43页
第4页 / 共43页
第5页 / 共43页
第6页 / 共43页
第7页 / 共43页
第8页 / 共43页
第9页 / 共43页
第10页 / 共43页
亲,该文档总共43页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
个人收集整理 勿做商业用途目录第一部分 功能代码 - 1 -1。DBO。 JAVA - 12.LOG.JAVA - 4-3。MD5.JAVA - 5-4。COMMON.JAVA - 6-5。CHECKCODE.JAVA - 8-6。LOGINSERVLETJAVA -8-7. TRAINBEAN.JAVA-13-第二部分 外部显示代码 - 22 -1。INDEX。 JSP-222.LOGIN。 JSP-263.ERROR.JSP-304.INDEX。 JSP-315.INDEX.JSP-33-第一部分 内部功能代码1. DBO 。 javapackage com.util ;import java。sql。*;import java.sql.DriverManager;import java 。 sql.ResultSet;import java 。 sql。 SQLException ;import javax.activation 。 DataSource;import java.sql. ;import java 。 sql。 DriverManager;import java 。 sql.ResultSet;import java 。 sql.SQLException;import java.sql.Statement;import javax 。 naming。 Context;import javax.naming.InitialContext ;public class DBO private Connection conn ;private Statement stmt ;private DataSource ds ;public DBO () /*打开数据库*/public void open( )try Class。forName (” orgg gjt。mm.mysql.Driver );conn = DriverManager.getConnection(jdbc:mysql:/localhost : 3306/cpyd?user=root&password=siminguseUnicode=true&characterEncoding=GBK ”) ;stmt=conn.createStatement( );System。out.println (”打开数据库连接);catch (Exception ex) System.err.println (”打开数据库时出错 : + ex.getMessage () );/*关闭数据库,将连接返还给连接池/public void close( ) try / connMgr 。 freeConnection ( java , conn ) ; conn 。 close();System 。 out。 println (”释放连接”);catch ( SQLException ex )System。 err.println (” 返还连接池出错:+ ex。 getMessage();/*执行查询*/public ResultSet executeQuery(String sql ) throws SQLException ResultSet rs = null ;rs = stmt 。 executeQuery(sql);System 。 out.println (”执行查询 );return rs;/执行增删改*/public int executeUpdate( String sql) throws SQLException int ret = 0;ret = stmt 。 executeUpdate(sql );System。out。printin (” 执行增删改”); return ret;/*将 SQL 语句加入到批处理*/pubiic void addBatch ( String sqi ) throws SQLException stmt。 addBatch (sqi);/执行批处理*/public int executeBatch () throws SQLException booiean isAuto=conn 。 getAutoCommit(); conn.setAutoCommit ( false); int updateCounts = stmt 。 executeBatch(); /conn 。 commit(); /conn 。 setAutoCommit(isAuto) ; /conn 。 setAutoCommit(true); return updateCounts ;public boolean getAutoCommit ( ) throws SQLException return conn.getAutoCommit() ;public void setAutoCommit ( boolean auto ) throws SQLException conn.setAutoCommit (auto);public void commit( ) throws SQLException conn 。 commit( ) ;/ this。 close();public void rollBack() throws SQLException conn 。 rollback ();/ this.close( );2. Log.javapackage com.util;/* 日志/import java。io。BufferedWriter ;import java.io.File ;import java.io 。 FileNotFoundException; import java.io 。 FileWriter ;import java.io 。 IOException ;import java 。 io。 PrintWriter ;public class Log public void addLog(String str)try File file=new File(c:/log.txt );”FileWriter fw=new FileWriter (file,true); BufferedWriter bw=new BufferedWriter(fw) ; PrintWriter pw = newPrintWriter(bw );pw.write(str );bw。 newLine (); /断行bw。 flush (); /将数据更新至文件pw。 close( );fw。 close( ); /关闭文件流 catch(FileNotFoundException e )System 。 out。 println ( 警告:日志文件没找到! !!”); e。 printStackTrace ( ); catch (IOException e) System 。 out.println ( 警告:日志文件 IO 错误! !);e。 printStackTrace ();3. MD5 。 javapackage com.util ;/MD5 密码加密类/import java.security. ;import java。security.spec。*;public final class MD5 public final static String MD5 (String s) char hexDigits = ,01,2, 3, ,5, 64, 7, 8, 9 ,,ac,, db,e ftry byte strTemp = s.getBytes ();MessageDigest mdTemp = MessageDigest 。 getInstance (”MD5”) mdTemp.update(strTemp );byte md = mdTemp 。 digest( );int j = md 。 length ;char str = new charj 2;int k = 0 ;for (int i = 0; i j;i+) byte byte0 = mdi ;strk+ = hexDigitsbyte0 4 & 0xf;strk+ = hexDigits byte0 & 0xf ;return new String(str );catch ( Exception e )return null;4. Common.javapackage com.util ;/* 常用方法类/import java。text。SimpleDateFormat;import java 。 util.Calendar;import java.util 。 Date;public final class Com mon/ 字符串 HTML 转换public static String turn (String str) while (str.indexOf (n) != 1)str = str 。 substring(0, str 。 indexOf( ”n) + + str。 substring (str.indexOf(n) + 1);while (str.indexOf (” ) !=-1)str = str.substring (0, str.indexOf ( ”) +nbsp ;”+ str.substring(str.indexOf ( ) + 1 );return str ;/ 返回日期 当前日期传入 0 一年之前传入 -1 三年后传入 3 public static String getDate (int num) SimpleDateFormat df = new SimpleDateFormat(yyyy-MMdd);Calendar c = Calendar 。 getInstance();c。 add(Calendar 。 YEAR, num );return df.format(c.getTime ();/ 数据库输出字符串的过滤public static String SQLStr(String str)if (str ! = null &
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号