2009年9月26日

一切都是那么的措手不及
你来的那么突然
令我一点防备都没有
我对你的到来很无奈
但我又不得不好好待你
你是我的眼中钉
我的手中刺
我发誓要杀掉你
不让你再祸害其他人
我在努力地做着我该做的事
天啊 又出bug了

posted @ 2009-09-26 15:54 BBT_soft 阅读(130) | 评论 (0)编辑 收藏

2009年8月8日

163          smtp.163.com                   pop.163.com

126          smtp.126.com                   pop3.126.com

188          smtp.188.com                    pop3.188.com

yeah       smtp.yeah.net                   pop3.yeah.net

sina         smtp.sina.com                   pop.sina.com

qq            smtp.qq.com                        pop.qq.com

yahoo       smtp.mail.yahoo.com.cn      pop.mail.yahoo.com.cn    yahoo前提是开通来信提醒业务

yahoo      smtp.mail.yahoo.cn              pop.mail.yahoo.cn

google     smtp.gmail.com                    pop.gmail.com

tom          smtp.tom.com                       pop.tom.com

sogou      smtp.mail.sogou.com            pop3.mail.sogou.com

sohu        smtp.sohu.com                     pop3.sohu.com

139          smtp.139.com                       pop.139.com

china        smtp.china.com                    pop.china.com    中华网邮箱

21CN        smtp.21cn.net                      pop3:pop.21cn.net     商务邮箱服务器

                 smtp.21cn.com                     pop3:pop.21cn.com    经济邮箱服务器
         
                 smtp.21cn.com                     pop3:pop.21cn.com 免费邮箱服务器

posted @ 2009-08-08 12:42 BBT_soft 阅读(2701) | 评论 (4)编辑 收藏

《think in java》中有这么一段话:

如果想比较两个对象的实际内容是否相同,又该如何操作呢?此时,必须使用所有对象都使用的特殊方法equals()。但这个方法不适用于"基本类型",基本类型直接使用==和!=即可。如:

Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
System.out.println(ne.equals(n2));

正如我们预计的那样,此时得到的结果是true。但事实上并不总是这么简单!假设您创建了自己的类,像下面这样:
class Value{
int i;
}
public class Test{

      public static void main(String[] args){
             Value v1 = new Value();
            Value v2 = new Value();
             System.out.println(v1.equals(v2));
    }
}
此时的结果又变回了false!

这是由于equals()的默认行为是比较引用。所以除非在自己的新类中重载equals()方法,否则不可能表现出我们希望的行为。

大多数Java类库都实现了用来比较对象内容的equals()方法,而非比较对象引用的equals()方法。

个人理解:equals()默认行为是比较引用,只是现在绝大多数Java类库都实现了用来比较对象内容的equals()方法,而并没有实现比较对象引用的equals()方法。所以现在说equals()比较的是内容,如果自己的类实现比较对象引用的equals()方法,也可以说equals()比较对象的引用,只是实现问题。

posted @ 2009-08-08 12:38 BBT_soft 阅读(1984) | 评论 (6)编辑 收藏

2009年8月2日

由于我用的是struts框架,就拿整个项目介绍:

1.首先把jstl的两个常用包jstl.jar、standard.jar加载到环境中

2.Action代码:(整个过程不需要了解,这儿方法就是返回一个封装Students对象的list,然后request.setAttribute("list", list)起来)

public ActionForward selectStudent(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
   StudentForm studentForm = (StudentForm) form;
   DBConnection dbconn = new DBConnection();
   Connection conn = dbconn.getConnection();
   StudentServiceFactory serviceFactory = new StudentServiceFactory();
   List list = serviceFactory.getStudentService().selectStudent(conn);
   request.setAttribute("list", list);
   try {
    conn.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
   return mapping.findForward("show");
}

3.show.jsp页面:

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>//这三句很重要

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'show.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
    查询结果如下: <br>
<table>
   <tr>
    <td>ID</td>
    <td>姓名</td>
   </tr>
  <c:forEach items="${list}" var="student">// items为list的一个迭代器,list为Action中传递过来的list,student为Student类对象
   <tr>
   <td>${student.id }</td>//输出student的id属性
    <td>${student.name }</td>//输出student的name属性
   </tr>
   </c:forEach>

<logic:iterate id="li" name="list" type="vo.Student">//id为自定义的名字,name为Action中传过来的list,type为实体类,包括完整路径,这里是vo.Student
    <tr>
     <td><bean:write name="li" property="id"/></td>//name为逻辑名,和logic:iterate id="li"中的id对应,property为实体类中真正的属性
     <td><bean:write name="li" property="name"/></td>
     <td><a href="student.do?method=deleteStudent&id=<bean:write name="li" property="id"/>">删除</a></td>
    </tr>
   </logic:iterate>


</table>
<a href="student.jsp">返回</a>
</body>
</html>

在JSP页面引入Struts标签库的时候有所不同:

struts1.3的为:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>或者<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

posted @ 2009-08-02 16:21 BBT_soft 阅读(2165) | 评论 (1)编辑 收藏

2009年6月13日

1.在项目的WebRoot/META-INF下建context.xml文件,注意必须在该目录下,Tomcat会自动找这个文件,Tomcat6.0以后就不用在web.xml中配置了:

<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true" crossContext="true">

<Resource
name="jdbc/test" ----------注意:test为项目名
auth="Container"----------该项为不变项
type="javax.sql.DataSource"----------该项为不变项
driverClassName="com.mysql.jdbc.Driver"----------数据库驱动名
url="jdbc:mysql://localhost:3306/haotian?autoReconnect=true"-------url
username="root"-----用户名
password="root"------密码
maxActive="10"   ------最大连接数
maxIdle="5"     --------最大空闲连接数
maxWait="-1"/>   ------最大等待毫秒数,-1为无限等待

</Context>

2.连接类:

public class DBConnection {
private Connection conn=null;
public Connection getConnection(){
  
    //生成上下文对象,通过它可以向容器发送别名.
    Context context;
    try {
     context = new InitialContext();
     //查找对象
     DataSource ds=(DataSource)context.lookup("java:comp/env/jdbc/test");//jdbc/test为配置文件中的name
     //得到连接
     try {
      conn=ds.getConnection();
     } catch (SQLException e) {
      e.printStackTrace();
     }
    } catch (NamingException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   
   
   return conn;
}

3.把MySQL5.0的驱动包放到Tomcat的lib目录下,注意:是Tomcat的lib,而不是项目的lib。(不知道为什么会这样,之前不用这种连接池的时候放在项目的lib中就可以连接成功,但是现在就不可以,个人认为可能是context.xml使得Tomcat找自身lib中的驱动包,而不是项目中的驱动包)

4.测试:

这里并非是在连接类里面写个main()就可以测试成功的,如果这样会出现下面的错误:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at util.DBConnection.getConnection(DBConnection.java:26)
at util.DBConnection.main(DBConnection.java:49)

所以,只有通过和前台结合才能测试连接是否成功。

总结:

context.xml必须在项目的WebRoot/META-INF,Tomcat会自动找这个文件;

数据库驱动包必须放在Tomcat的lib目录下(可能是Tomcat会根据context.xml在自身的lib目录下找驱动包);

不可以直接在连接类中写main()测试,必须和前台结合;

posted @ 2009-06-13 09:21 BBT_soft 阅读(1148) | 评论 (5)编辑 收藏

仅列出标题