我的博客我做主

我的未来不是梦!
posts - 9, comments - 10, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

2010年7月15日

感谢大家都我博客的关注和关系,现在将博客迁移到www.v5cn.cn上面了,有兴趣的童鞋可以到上面寻找自己感兴趣的技术博文,主要包括WorldWind,Lucene等技术。www.v5cn.cn

posted @ 2013-10-08 14:02 平常心 阅读(137) | 评论 (0)编辑 收藏

更多博客请查看:http://www.v5cn.cn
在安装好Sql Server2005后默认是不支持JTA分布式事务的,要进行一下额外的设置才可以支持JTA事务。
那么如何让Sql Server2005具有JTA事务那,那大家就跟我一步一步做吧!
第一步:
    下载Sql Server2005的JDBC驱动。下载完成后得到的是一个exe文件:“sqljdbc_1.0.809.102_chs.exe”。
    双击打开:
    
    点击Browse... 选择要解压的目录。解压后得到:
    
    其中:sqljdbc.jar是Java连接Sql Server2005的驱动程序。
    打开xa目录:
    
    可以看到x64目录和x86目录和xa_install.sql文件
    我们这里选择x86也就是32位的机器。打开可以看到sqljdbc_xa.dll文件
    复制该文件到Sql Server2005的安装目录中的Binn文件夹下面。(Sql Server2005的安装目录下面有很多Binn,我也不知道那个复制那个不复制,所以我就都复制了。
    有知道的朋友可以回复告诉大家和我!)
第二步:
    打开操作系统win7和XP:
        win7下面是:控制面板--> 系统和安全-->管理工具-->组件服务-->计算机-->Distributed Transaction Coordinator-->右键,【本地DTC】,【属性】选择【安全】勾选
        启用XA事务,点击确认。服务会重启。
        XP:控制面板-->管理工具-->组件服务-->计算机-->我的电脑-->右键,【属性】如图:
        
        
        勾选【启用XA事务】点击确定完成。
第三步:
    复制xa_install.sql到Sql Server2005的查询分析器中执行会创建一个角色:sqlJDBCXAUser
    因为Sql Server2005默认的超级管理员sa无法绑定sqlJDBCXAUser,所以我们重新创建一个超级管理员名称dba
    然后把sqlJDBCXAUser授权给他就可以了:
    1. 创建用户和授权:
        a). 创建用户:
            
            b). 登录名的基本配置:
                
                
                
    点击确认用户创建成功!重启数据库服务。
    使用刚创建的用户登录。使用JTA分布式事务时也使用该用户登录,就OK了!

posted @ 2010-10-15 15:16 平常心 阅读(2373) | 评论 (0)编辑 收藏

更多博客请查看:http://www.v5cn.cn
1.创建一个Web工程,添加Struts2支持。
2.创建两个实体类:
a). Mother(母亲)的Java类。
package struts.map.entity;

import java.io.Serializable;

public class Mother implements Serializable {

private static final long serialVersionUID = 1L;

private int motherId;        //母亲ID
    private String motherName;        //母亲名字
    public int getMotherId() {
return motherId;
}
public void setMotherId(int motherId) {
this.motherId = motherId;
}
public String getMotherName() {
return motherName;
}
public void setMotherName(String motherName) {
this.motherName = motherName;
}
}

b).Children(孩子)的Java类

package struts.map.entity;

import java.io.Serializable;

public class Children implements Serializable {

private static final long serialVersionUID = 1L;

private int childId;        //孩子ID
    private int motherId;        //母亲的ID
    private String childName;        //孩子名字
    
public int getChildId() {
return childId;
}
public void setChildId(int childId) {
this.childId = childId;
}
public int getMotherId() {
return motherId;
}
public void setMotherId(int motherId) {
this.motherId = motherId;
}
public String getChildName() {
return childName;
}
public void setChildName(String childName) {
this.childName = childName;
}
}

 

3. 创建一个Action,并创建一位母亲和她的孩子。

package struts.map.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import struts.map.entity.Children;
import struts.map.entity.Mother;

import com.opensymphony.xwork2.ActionSupport;

public class Struts2_Map extends ActionSupport {

private static final long serialVersionUID = 1L;

private Map<Mother,List<Children>> motherChildn;

public Map<Mother, List<Children>> getMotherChildn() {
return motherChildn;
}

@Override
public String execute() throws Exception {
/*-------------------以对象做父节点的键,List做子节点的值,的Map-----------------------*/
Mother mother 
= new Mother();
mother.setMotherId(
10000);
mother.setMotherName(
"花木兰");

Children children1 
= new Children();
children1.setChildId(
10000);
children1.setMotherId(
10000);
children1.setChildName(
"小花木兰1");

Children children2 
= new Children();
children2.setChildId(
10001);
children2.setMotherId(
10000);
children2.setChildName(
"小花木兰2");

Children children3 
= new Children();
children3.setChildId(
10002);
children3.setMotherId(
10000);
children3.setChildName(
"小花木兰3");

motherChildn 
= new HashMap<Mother,List<Children>>();

List
<Children> childrens = new ArrayList<Children>();

childrens.add(children1);
childrens.add(children2);
childrens.add(children3);

motherChildn.put(mother,childrens);

return SUCCESS;
}
}

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="map" extends="struts-default">
<action name="struts_map" class="struts.map.test.Struts2_Map">
<result>result.jsp</result>
</action>
</package>
</struts>  

4.创建两个页面:
a).跳转页面:
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Struts_Map</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">
</head>

<body>
<href="struts_map.action">查看Map</a>
</body>
</html>

b).最终页面,也是作重要的页面:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Struts_Map</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">
</head>

<body>
<div>
<h3>-----------------以对象做父节点的键,List做子节点的值,的Map--------------------</h3>
<s:iterator var="mc" value="motherChildn">
<div>
母亲名称:
<s:property value="key.motherName"/>
</div>
<s:iterator var="ch" value="value">
<div>
&nbsp;&nbsp;&nbsp;孩子名称:<s:property value="#ch.childName"/>
</div>
</s:iterator>
</s:iterator>
</div>
</body>
</html>

最终运行结果:

posted @ 2010-08-26 22:18 平常心 阅读(6864) | 评论 (0)编辑 收藏

更多博客请查看:http://www.v5cn.cn
第一步:下载安装的文件
    1. MySQL:下载地址mysql-5.1.49-win32.msi
2. Apache: 下载地址httpd-2.2.16-win32-x86-openssl-0.9.8o.msi
3. PHP5.3.3  下载地址php-5.3.3-Win32-VC6-x86        注意:一定要下载php-5.3.3-Win32-VC6-x86版本
的,不要下载php-5.3.3-nts-Win32-VC6-x86版本,更不要下载VC9版本的,因为他是IIS服务器安装版本。
 第二步:安装文件
1. 在要安装的磁盘建一个文件夹(笔者的做法是在D盘的根目录下创建一个php文件夹D:\php)。
2. 安装Apache服务器,安装完成后的目录结果是:D:\php\Apache。
3. 把下载的php-5.3.3-Win32-VC6-x86解压的D:\php目录中,可以把文件夹的名字改短,结果D:\php\php5
4. 安装MySql数据库,它的安装和一般情况一样。笔者把他安装在(D:\php\MySQL)和php同目录。
第三步:配置PHP5.3.3
    1. 配置PHP5.3.3,打开php安装目录(笔者是D:\php\php5)可以看到目录下有两个这样的文件php.ini-    development和php.ini-production,第一个是开发使用的配置文件,第二个是标准的生产环境的配置。
2. 选择php.ini-development复制一份到同目录下,并改名为php.ini使用文本工具打开,查找extension_dir,可以
看到两个,选择On windows:下面的那个并去得前面的分号修改为extension_dir = "D:/php/php5/ext",读者根
据自己的目录结构配置,目的是找到和php.ini同目录下的ext文件夹中的扩展库。
3. 查找extension=php_,去掉extension=php_curl.dll、extension=php_gd2.dll、extension=php_mbstring.dll、
extension=php_mysql.dll、extension=php_mysqli.dll、extension=php_pdo_mysql.dll、extension=php_xmlrpc.dll
前面
的分号。查找short_open_tag = Off把它修改成short_open_tag = On,让其支持短标签。
4. 复制php5ts.dll文件到WINDOWS/system32目录下,只有php-5.3.3-Win32-VC6-x86版本中才有php5ts.dll 
        php-5.3.3-nts-Win32-VC6-x86版本是没有的。
第四步:配置Apache
1. 打开Apache目录下conf目录中的
httpd.conf文件,查找#LoadModule,在其末尾处大概是128行的地方
添加:
 LoadModule php5_module "D:/php/php5/php5apache2_2.dll"
PHPIniDir "D:/php/php5"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html

目录结构根据用户自己目录配置。
2. 查找DirectoryIndex index.html 将其修改成DirectoryIndex index.php default.php index.html index.htm default.html 
default.htm
    3. 查找DocumentRoot将其修改为指向你需要放置web文件的文件夹上(笔者在D:/php目录中创建了一个
www文件夹)所以DocumentRoot就是DocumentRoot "D:/php/www",读者可以根据自己配置来修改。
4. 查找<Directory将其修改为你自己配置的DocumentRoot的路径(笔者是<Directory "D:/php/www">)
第五步:测试php+Apache+MySql是否配置成功
1. 打开MySql在MySql中创建一个新数据库和表。(笔者是userInfo数据库和users表就有id和name两个字段)
测试吗?简单就好,呵呵!!
2. 在上面创建的www文件夹中创建一个index.php文件使用EditPlus或者其他文本工具打开。
3. 写入:
<?
    
$DB_HOST = "localhost";
    
$DB_USER = "root";
    
$DB_PASS = "root";
    
$DB_NAME = "userInfo";

    
mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
    
mysql_select_db($DB_NAME);
    
    
mysql_query("set NAMES gb2312");
    
$sql = "Select * From users";
    
$result = mysql_query($sql);
    
while($data=mysql_fetch_array($result)){
        
echo "------------------------";
        
echo $data['id']."<br/>";
        
echo $data['name']."<br/>";
    }
    
mysql_close();
?>
4.启动Apache服务器,在浏览器输入http://localhost/回车。
如果看到下图:表示我们大功告成了!祝贺祝贺!

posted @ 2010-08-07 12:13 平常心 阅读(8094) | 评论 (6)编辑 收藏

更多博客请查看:http://www.v5cn.cn
GSON是Google公司的Java对象序列化成JSON的插件
下载地址:http://code.google.com/p/google-gson/downloads/list
下载下来以后:把gson-1.4.jar这个jar文件加到工程里。
Action的使用方式是:
package test.gson;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;

public class TestGson extends ActionSupport {
    
private static final long serialVersionUID = 1L;
    
private Users user;
    
public Users getUser() {
        
return user;
    }

    
public void setUser(Users user) {
        
this.user = user;
    }

    @Override
    
public String execute() throws Exception {
        user 
= new Users();
        user.setId(
10000);
        user.setUserName(
"zhangsan");
        user.setPwd(
"000000");
        user.setEmail(
"zhangsan@sina.com");
        
        Gson g  
= new Gson();
        String json 
= g.toJson(user);
        HttpServletResponse response 
= ServletActionContext.getResponse();
        response.setContentType(
"application/json;charset=utf-8");
        response.setHeader(
"Cache-Control","no-cache");
        
        PrintWriter pw 
= response.getWriter();
        pw.print(json);
        pw.flush();
        pw.close();
        
        
        
return null;
    }

}

其中response.setContentType("application/json;charset=utf-8");是最重要的
一定要把ContentType设置成application/json形式
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    
<package name="jsons" extends="struts-default" namespace="/">
        
<action name="testGson" class="test.gson.TestGson"></action>
    
</package>
</struts>
Gson其实可以用在所有的Javaweb工程了,不一定是Struts2

posted @ 2010-07-29 18:15 平常心 阅读(1408) | 评论 (0)编辑 收藏

更多博客请查看:http://www.v5cn.cn
只需在XML配置就可以了,配置方式是:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    
<package name="jsons" extends="json-default" namespace="/">
        
<action name="getJSON" class="test.json.Users">
            
<result name="success" type="json">
                
<!-- excludeProperties表示不包含的属性(可以使用正则表达式匹配) -->
                
<param name="excludeProperties">
                    id,userName
                
</param>
                
<!-- includeProperties表示包含序列化的属性(可以使用正则表达式匹配) -->
                
<param name="includeProperties">
                    pwd,address
                
</param>
            
</result>
        
</action>
    
</package>
</struts>    
默认情况下Struts2插件的序列化是从Action开始的如果需要序列化从指定的方式开始请使用:
<!-- 这样序列化工作就从birthday开始了 -->
                
<param name="root">
                    birthday
                
</param>
Struts2JSONPlugin使用文档.pdf

posted @ 2010-07-29 16:29 平常心 阅读(909) | 评论 (1)编辑 收藏

更多博客请查看:http://www.v5cn.cn
在使用Struts2的JSON插件,实现Action中的属性序列化成JSON对象时默认JSON插件会把所有Action中包含getter方法的属性都序列化到JSON对象中。但是有时候我们并不需要太多的属性,或者只需要一个属性。那么怎样控制属性序列化到JSON对象中哪?Struts2的JSON插件为我们提供了两种方式,第一:使用注解的方式控制,第二:使用Struts2的struts.xml配置文件的方式。

这一讲我们主要介绍注解方式。如果大家还不会Struts2+JSON+JQuery的交互方式请查看 http://zyw090111.javaeye.comStruts2+jQuery+JSON实现异步交互的文章

我们要使用JSON的注解是@JSON这个类共有是个属性分别是:
1. name    String 类型     用户为属性起一个别名(我们序列化到JSON对象中的键默认是属性名称,如果使用了name属性那么键是name起的名字);
2. serialize  Boolean类型   默认为true 也就是可以被序列化,如果设为false那么该属性将不包含在JSON对象中;
3. format  String类型  主要是对日期进行格式化
4. deserialize Boolean类型 默认为true,它是指反序列化,和serialize相反。
请看代码:
package test.json;

import java.util.Date;

import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings(
"serial")
public class Users extends ActionSupport {
    
private int id;
    
private String userName;
    
private String pwd;
    
private String address;
    
private Date birthday;
    
public int getId() {
        
return id;
    }

    
public void setId(int id) {
        
this.id = id;
    }

    @JSON(serialize
=false)
    
public String getUserName() {
        
return userName;
    }

    
    
public void setUserName(String userName) {
        
this.userName = userName;
    }

    @JSON(name
="mm")
    
public String getPwd() {
        
return pwd;
    }

    
public void setPwd(String pwd) {
        
this.pwd = pwd;
    }

    
public String getAddress() {
        
return address;
    }

    
public void setAddress(String address) {
        
this.address = address;
    }

    @JSON(format
="yy-MM-dd")
    
public Date getBirthday() {
        
return birthday;
    }

    
public void setBirthday(Date birthday) {
        
this.birthday = birthday;
    }

    @Override
    
public String execute() throws Exception {
        
        
this.id = 10000;
        
this.userName = "zhangsan";
        
this.pwd = "00000";
        
this.address = "xian";
        
this.birthday = new Date();
        
        
return SUCCESS;
    }

}

posted @ 2010-07-29 16:15 平常心 阅读(3357) | 评论 (3)编辑 收藏

更多博客请查看:http://www.v5cn.cn
1. 去掉#号:
在项目上右键选择Properties-->Flex Compiler去掉Enable integration with browser navigation前面的钩点击OK
2. 在项目<mx:Application pageTitle="项目名称"/>
修改完毕!

posted @ 2010-07-19 15:59 平常心 阅读(313) | 评论 (0)编辑 收藏

更多博客请查看:http://www.v5cn.cn
昨天BlogJava的博客开通了!2010-07-14

posted @ 2010-07-15 14:17 平常心 阅读(155) | 评论 (0)编辑 收藏