| 安's profile有间客栈PhotosBlogLists | Help |
|
July 01 jquery-autocomplete学习jquery-autocomplete学习 一、用前必备 二、使用 autocomplete( url or data, options ) Returns: jQuery
Js代码 var emails = [ $("#suggest13").autocomplete(emails, {
1.网上有人说对中文的检索时处理有问题,经过测试此版本没有问题^-^ 2.在使用远程地址时,它默认传入的参数是:q(输入值),limit(返回结果的最大值),可以使用extraParams传入其他的参数 3.autocomplete在使用ajax传递参数时,默认使用了get方式传递,也实在是没有找到可以通过参数提交post方式的办法。 4.在使用ajax方式时,远程地址返回结果是:使用\n分割每行数据,每行数据中使用|分割每个元素 June 30 jQuery ajax乱码问题解决一、测试环境 二、测试方法 1.使用get方式 服务器端java代码: 客户端js代码: $.ajax({url: "2.jsp",type: "get",data: "name=中文",success: function(response){ $.get("2.jsp", { name: "中文" },function(response){ $.get("2.jsp", "name=中文",function(response){
服务器端java代码: 客户端js代码: $.ajax({url: "3.jsp",type: "post",data: {name:"中文"},success: function(response){ $.post("3.jsp", { name: "中文" },function(response){ $.post("3.jsp", "name=中文",function(response){ 三、使用filter public void doFilter(ServletRequest request, ServletResponse response, jQuery在使用ajax的时候会在header中加入X-Requested-With,值为:XMLHttpRequest,filter中判断是jQuery的ajax请求时就把字符编码设为utf8,这样可以解决post提交中的中文乱码问题,不需要在代码中设置request.setCharacterEncoding("UTF-8"); 对于get方式的中文乱码问题,建议不使用get方式提交中文,统统改为post ^-^ 为了和prototype.js处理中文的方式一致,可以使用如下的方式,自定义header中的属性RequestType
$.ajax({
url: "3.jsp", type: "post", data: {name:"中文"}, beforeSend: function(XMLHttpRequest){ XMLHttpRequest.setRequestHeader("RequestType", "ajax"); alert("开始"); }, success: function(data, textStatus){ alert(data); }, error: function(XMLHttpRequest, textStatus, errorThrown){ alert("错误:" + textStatus); }, complete: function(XMLHttpRequest, textStatus){ alert("完成:" + textStatus); } }); filter代码如下: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; if (req.getHeader("RequestType") != null && req.getHeader("RequestType").equalsIgnoreCase("ajax"))) { request.setCharacterEncoding("utf-8"); } else { request.setCharacterEncoding("gbk"); } chain.doFilter(request, response); } June 28 jquery-validate学习一、用前必备
官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/
API: http://jquery.bassistance.de/api-browser/plugins.html 当前版本:1.5.5
需要JQuery版本:1.2.6+, 兼容 1.3.2 <script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/jquery.validate.js" type="text/javascript"></script> 二、默认校验规则 (1)required:true 必输字段
(2)remote:"check.php" 使用ajax方法调用check.php验证输入值 (3)email:true 必须输入正确格式的电子邮件 (4)url:true 必须输入正确格式的网址 (5)date:true 必须输入正确格式的日期 (6)dateISO:true 必须输入正确格式的日期(ISO),例如:2009-06-23,1998/01/22 只验证格式,不验证有效性 (7)number:true 必须输入合法的数字(负数,小数) (8)digits:true 必须输入整数 (9)creditcard: 必须输入合法的信用卡号 (10)equalTo:"#field" 输入值必须和#field相同 (11)accept: 输入拥有合法后缀名的字符串(上传文件的后缀) (12)maxlength:5 输入长度最多是5的字符串(汉字算一个字符) (13)minlength:10 输入长度最小是10的字符串(汉字算一个字符) (14)rangelength:[5,10] 输入长度必须介于 5 和 10 之间的字符串")(汉字算一个字符) (15)range:[5,10] 输入值必须介于 5 和 10 之间 (16)max:5 输入值不能大于5 (17)min:10 输入值不能小于10 三、默认的提示 messages: {
required: "This field is required.", remote: "Please fix this field.", email: "Please enter a valid email address.", url: "Please enter a valid URL.", date: "Please enter a valid date.", dateISO: "Please enter a valid date (ISO).", dateDE: "Bitte geben Sie ein g眉ltiges Datum ein.", number: "Please enter a valid number.", numberDE: "Bitte geben Sie eine Nummer ein.", digits: "Please enter only digits", creditcard: "Please enter a valid credit card number.", equalTo: "Please enter the same value again.", accept: "Please enter a value with a valid extension.", maxlength: $.validator.format("Please enter no more than {0} characters."), minlength: $.validator.format("Please enter at least {0} characters."), rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."), range: $.validator.format("Please enter a value between {0} and {1}."), max: $.validator.format("Please enter a value less than or equal to {0}."), min: $.validator.format("Please enter a value greater than or equal to {0}.") }, 如需要修改,可在js代码中加入:
jQuery.extend(jQuery.validator.messages, {
required: "必选字段", remote: "请修正该字段", email: "请输入正确格式的电子邮件", url: "请输入合法的网址", date: "请输入合法的日期", dateISO: "请输入合法的日期 (ISO).", number: "请输入合法的数字", digits: "只能输入整数", creditcard: "请输入合法的信用卡号", equalTo: "请再次输入相同的值", accept: "请输入拥有合法后缀名的字符串", maxlength: jQuery.validator.format("请输入一个长度最多是 {0} 的字符串"), minlength: jQuery.validator.format("请输入一个长度最少是 {0} 的字符串"), rangelength: jQuery.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"), range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"), max: jQuery.validator.format("请输入一个最大为 {0} 的值"), min: jQuery.validator.format("请输入一个最小为 {0} 的值") }); 推荐做法,将此文件放入messages_cn.js中,在页面中引入
<script src="../js/messages_cn.js" type="text/javascript"></script> 四、使用方式 1.将校验规则写到控件中
<script src="../js/jquery.js" type="text/javascript"></script> <script src="../js/jquery.validate.js" type="text/javascript"></script> <script src="./js/jquery.metadata.js" type="text/javascript"></script> $().ready(function() {
$("#signupForm").validate(); }); <form id="signupForm" method="get" action=""> <p> <label for="firstname">Firstname</label> <input id="firstname" name="firstname" class="required" /> </p> <p> <label for="email">E-Mail</label> <input id="email" name="email" class="required email" /> </p> <p> <label for="password">Password</label> <input id="password" name="password" type="password" class="{required:true,minlength:5}" /> </p> <p> <label for="confirm_password">确认密码</label> <input id="confirm_password" name="confirm_password" type="password" class="{required:true,minlength:5,equalTo:'#password'}" /> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> </form> 使用class="{}"的方式,必须引入包:jquery.metadata.js
可以使用如下的方法,修改提示内容:
class="{required:true,minlength:5,messages:{required:'请输入内容'}}" 在使用equalTo关键字时,后面的内容必须加上引号,如下代码:
class="{required:true,minlength:5,equalTo:'#password'}" 另外一个方式,使用关键字:meta(为了元数据使用其他插件你要包装 你的验证规则 在他们自己的项目中可以用这个特殊的选项)
Tell the validation plugin to look inside a validate-property in metadata for validation rules. 例如: meta: "validate" <input id="password" name="password" type="password" class="{validate:{required:true,minlength:5}}" /> 再有一种方式: $.metadata.setType("attr", "validate"); 这样可以使用validate="{required:true}"的方式,或者class="required",但class="{required:true,minlength:5}"将不起作用
2.将校验规则写到代码中
$().ready(function() { $("#signupForm").validate({ rules: { firstname: "required", email: { required: true, email: true }, password: { required: true, minlength: 5 }, confirm_password: { required: true, minlength: 5, equalTo: "#password" } }, messages: { firstname: "请输入姓名", email: { required: "请输入Email地址", email: "请输入正确的email地址" }, password: { required: "请输入密码", minlength: jQuery.format("密码不能小于{0}个字符") }, confirm_password: { required: "请输入确认密码", minlength: "确认密码不能小于5个字符", equalTo: "两次输入密码不一致不一致" } } }); }); //messages处,如果某个控件没有message,将调用默认的信息
<form id="signupForm" method="get" action=""> <p> <label for="firstname">Firstname</label> <input id="firstname" name="firstname" /> </p> <p> <label for="email">E-Mail</label> <input id="email" name="email" /> </p> <p> <label for="password">Password</label> <input id="password" name="password" type="password" /> </p> <p> <label for="confirm_password">确认密码</label> <input id="confirm_password" name="confirm_password" type="password" /> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> </form> required:true 必须有值
required:"#aa:checked"表达式的值为真,则需要验证 required:function(){}返回为真,表时需要验证 后边两种常用于,表单中需要同时填或不填的元素 五、常用方法及注意问题
1.用其他方式替代默认的SUBMIT
$().ready(function() {
$("#signupForm").validate({ submitHandler:function(form){ alert("submitted"); form.submit(); } }); }); 可以设置validate的默认值,写法如下:
$.validator.setDefaults({ submitHandler: function(form) { alert("submitted!");form.submit(); } }); 如果想提交表单, 需要使用form.submit()而不要使用$(form).submit()
2.debug,如果这个参数为true,那么表单不会提交,只进行检查,调试时十分方便 $().ready(function() { $("#signupForm").validate({ debug:true }); }); 如果一个页面中有多个表单,用 $.validator.setDefaults({ debug: true }) 3.ignore:忽略某些元素不验证 ignore: ".ignore" 4.errorPlacement:Callback Default: 把错误信息放在验证的元素后面 指明错误放置的位置,默认情况是:error.appendTo(element.parent());即把错误信息放在验证的元素后面 errorPlacement: function(error, element) { error.appendTo(element.parent()); } //示例:
<tr> <td class="label"><label id="lfirstname" for="firstname">First Name</label></td> <td class="field"><input id="firstname" name="firstname" type="text" value="" maxlength="100" /></td> <td class="status"></td> </tr> <tr> <td style="padding-right: 5px;"> <input id="dateformat_eu" name="dateformat" type="radio" value="0" /> <label id="ldateformat_eu" for="dateformat_eu">14/02/07</label> </td> <td style="padding-left: 5px;"> <input id="dateformat_am" name="dateformat" type="radio" value="1" /> <label id="ldateformat_am" for="dateformat_am">02/14/07</label> </td> <td></td> </tr> <tr> <td class="label"> </td> <td class="field" colspan="2"> <div id="termswrap"> <input id="terms" type="checkbox" name="terms" /> <label id="lterms" for="terms">I have read and accept the Terms of Use.</label> </div> </td> </tr> errorPlacement: function(error, element) {
if ( element.is(":radio") ) error.appendTo( element.parent().next().next() ); else if ( element.is(":checkbox") ) error.appendTo ( element.next() ); else error.appendTo( element.parent().next() ); } 代码的作用是:一般情况下把错误信息显示在<td class="status"></td>中,如果是radio显示在<td></td>中,如果是checkbox显示在内容的后面
errorClass:String Default: "error"
指定错误提示的css类名,可以自定义错误提示的样式 errorElement:String Default: "label"
用什么标签标记错误,默认的是label你可以改成em errorContainer:Selector
显示或者隐藏验证信息,可以自动实现有错误信息出现时把容器属性变为显示,无错误时隐藏,用处不大 errorContainer: "#messageBox1, #messageBox2" errorLabelContainer:Selector
把错误信息统一放在一个容器里面。 wrapper:String
用什么标签再把上边的errorELement包起来 一般这三个属性同时使用,实现在一个容器内显示所有错误提示的功能,并且没有信息时自动隐藏
errorContainer: "div.error",
errorLabelContainer: $("#signupForm div.error"), wrapper: "li" 设置错误提示的样式,可以增加图标显示
input.error { border: 1px solid red; }
label.error { background:url("./demo/images/unchecked.gif") no-repeat 0px 0px; padding-left: 16px;
padding-bottom: 2px;
font-weight: bold;
color: #EA5200;
} label.checked { background:url("./demo/images/checked.gif") no-repeat 0px 0px; } success:String,Callback
要验证的元素通过验证后的动作,如果跟一个字符串,会当做一个css类,也可跟一个函数 success: function(label) { // set as text for IE label.html(" ").addClass("checked"); //label.addClass("valid").text("Ok!") } 添加"valid" 到验证元素, 在CSS中定义的样式<style>label.valid {}</style> success: "valid" nsubmit: Boolean Default: true
提交时验证. 设置唯false就用其他方法去验证 onfocusout:Boolean Default: true 失去焦点是验证(不包括checkboxes/radio buttons) onkeyup:Boolean Default: true 在keyup时验证. onclick:Boolean Default: true 在checkboxes 和 radio 点击时验证 focusInvalid:Boolean Default: true 提交表单后,未通过验证的表单(第一个或提交之前获得焦点的未通过验证的表单)会获得焦点 focusCleanup:Boolean Default: false 如果是true那么当未通过验证的元素获得焦点时,移除错误提示。避免和 focusInvalid 一起用 // 重置表单
$().ready(function() { var validator = $("#signupForm").validate({ submitHandler:function(form){ alert("submitted"); form.submit(); } }); $("#reset").click(function() { validator.resetForm(); }); });
remote:URL
使用ajax方式进行验证,默认会提交当前验证的值到远程地址,如果需要提交其他的值,可以使用data选项 remote: "check-email.php"
remote: {
url: "check-email.php", //后台处理程序 type: "post", //数据发送方式 dataType: "json", //接受数据格式 data: { //要传递的数据 username: function() { return $("#username").val(); } } } 远程地址只能输出 "true" 或 "false",不能有其它输出 addMethod:name, method, message
自定义验证方法 // 中文字两个字节 jQuery.validator.addMethod("byteRangeLength", function(value, element, param) { var length = value.length; for(var i = 0; i < value.length; i++){ if(value.charCodeAt(i) > 127){ length++; } } return this.optional(element) || ( length >= param[0] && length <= param[1] ); }, $.validator.format("请确保输入的值在{0}-{1}个字节之间(一个中文字算2个字节)")); // 邮政编码验证 jQuery.validator.addMethod("isZipCode", function(value, element) { var tel = /^[0-9]{6}$/; return this.optional(element) || (tel.test(value)); }, "请正确填写您的邮政编码"); radio和checkbox、select的验证 radio的required表示必须选中一个
<input type="radio" id="gender_male" value="m" name="gender" class="{required:true}" /> <input type="radio" id="gender_female" value="f" name="gender"/> checkbox的required表示必须选中
<input type="checkbox" class="checkbox" id="agree" name="agree" class="{required:true}" /> checkbox的minlength表示必须选中的最小个数,maxlength表示最大的选中个数,rangelength:[2,3]表示选中个数区间
<input type="checkbox" class="checkbox" id="spam_email" value="email" name="spam[]" class="{required:true, minlength:2}" /> <input type="checkbox" class="checkbox" id="spam_phone" value="phone" name="spam[]" /> <input type="checkbox" class="checkbox" id="spam_mail" value="mail" name="spam[]" /> select的required表示选中的value不能为空 <select id="jungle" name="jungle" title="Please select something!" class="{required:true}"> <option value=""></option> <option value="1">Buga</option> <option value="2">Baga</option> <option value="3">Oi</option> </select> select的minlength表示选中的最小个数(可多选的select),maxlength表示最大的选中个数,rangelength:[2,3]表示选中个数区间 <select id="fruit" name="fruit" title="Please select at least two fruits" class="{required:true, minlength:2}" multiple="multiple"> <option value="b">Banana</option> <option value="a">Apple</option> <option value="p">Peach</option> <option value="t">Turtle</option> </select> June 23 JAVA socket连接服务器的connect timeout设置在使用java中的socket连接服务器时,使用
Socket socket = new Socket(serverip, serverport);
只能通过setSoTimeout设置它的超时时间,即如果超过了指定的时间还读不到任何数据,程序将抛出一个java.io.InterruptedIOException异常。
connect timeout没有设置的话,会使用系统默认时间,有些服务器此时间过长,导致连接不上服务器会等待很长时间后才会返回connect timeout异常
要设置connect timeout属性:
SocketAddress socketAddress = new InetSocketAddress(_ip, _port); Socket s = new Socket(); s.connect(socketAddress, 5000); // 5 秒connect timeout超时 s.setSoTimeout(5000); // 5 秒io超时 June 11 apache使用jk整合tomcat的JK配置JK 的配置最关键的有三个文件,分别是
httpd.conf
Apache 服务器的配置文件,用来加载 JK 模块以及指定 JK 配置文件信息 workers.properties
到 Tomcat 服务器的连接定义文件 uriworkermap.properties
URI 映射文件,用来指定哪些 URL 由 Tomcat 处理,你也可以直接在 httpd.conf 中配置这些 URI,但是独立这些配置的好处是 JK 模块会定期更新该文件的内容,使得我们修改配置的时候无需重新启动 Apache 服务器。 其中第二、三个配置文件名都可以自定义。下面是一个典型的 httpd.conf 对 JK 的配置
# (httpd.conf) # 加载 mod_jk 模块 LoadModule jk_module modules/mod_jk.so #
# Configure mod_jk # JkWorkersFile conf/workers.properties
#JkMountFile conf/uriworkermap.properties JkLogFile logs/mod_jk.log JkLogLevel warn JkMount /jkmanager|/* jkstatus JkMount /*.jsp controller JkMount /*.do controller 或者把以上的配置写到文件jk.conf中,在httpd.conf中增加Include conf/jk.conf 接下来我们在 Apache 的 conf 目录下新建两个文件分别是 workers.properties、uriworkermap.properties。这两个文件的内容大概如下
#
# workers.properties # # list the workers by name worker.list=controller, jkstatus
# localhost server 1
# ------------------------ worker.s1.port=8109 worker.s1.host=localhost worker.s1.type=ajp13 worker.s1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多 # localhost server 2
# ------------------------ worker.s2.port=8209 worker.s2.host=localhost worker.s2.type=ajp13 worker.s2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多 worker.controller.type=lb
worker.controller.balanced_workers=s1, s2 worker.controller.sticky_session=1 worker.jkstatus.type=status
首先我们配置了两个类型为 ajp13 的 worker 分别是 s1 和 s2,它们指向同一台服务器上运行在两个不同端口 8109 和 8209 的 Tomcat 上。接下来我们配置了一个类型为 lb(也就是负载均衡的意思)的 worker,它的名字是 controller,这是一个逻辑的 worker,它用来管理前面配置的两个物理连接 s1 和 s2。最后还配置了一个类型为 status 的 worker,这是用来监控 JK 本身的模块。有了这三个 worker 还不够,我们还需要告诉 JK,哪些 worker 是可用的,所以就有 worker.list = controller, jkstatus 这行配置。 简单的方式,只有一个worker
worker.list=ajp13 worker.ajp13.port=9008 worker.ajp13.host=localhost worker.ajp13.type=ajp13 接下来便是 URI 的映射配置了,我们需要指定哪些链接是由 Tomcat 处理的,哪些是由 Apache 直接处理的,看看下面这个文件你就能明白其中配置的意义
/*=controller /jkstatus=status !/*.gif=controller
!/*.jpg=controller !/*.png=controller !/*.css=controller !/*.js=controller !/*.htm=controller !/*.html=controller 所有的请求都由 controller 这个 worker 进行处理,但是有几个例外,/jkstatus 请求由 status 这个 worker 处理。另外这个配置中每一行数据前面的感叹号是什么意思呢?感叹号表示接下来的 URI 不要由 JK 进行处理,也就是 Apache 直接处理所有的图片、css 文件、js 文件以及静态 html 文本文件。 # Mapping the URI /myapp1 and everything under /myapp1/:
/myapp1=myworker-a /myapp1/*=myworker-a # Mapping all URI which end with a common suffix: *.jsp=myworker *.do=myworker # Mapping the URI /myapp1 and everything under /myapp1/:
/myapp1|/*=myworker-a # Mapping the URI /myapp and everything under /myapp/: /myapp|/*=myworker # Exclude the subdirectory static: !/myapp/static|/*=myworker # Exclude some suffixes: !*.html=myworker # Mapping the webapps /myapp1 and /myapp2:
/myapp1|/*=myworker1 /myapp2|/*=myworker2 # Exclude the all subdirectories static for all workers: !/*/static|/*=* # Exclude some suffixes for all workers: !*.html=* 通过对 workers.properties 和 uriworkermap.properties 的配置,可以有各种各样的组合来满足我们前面提出对一个 web 网站的要求。
通过新增的redirect和activation属性可以实现active standby模式
# The advanced router LB worker worker.list=router # Define a worker using ajp13
worker.worker1.port=8009 worker.worker1.host=node1.domain.org worker.worker1.type=ajp13 worker.worker1.lbfactor=1 # Define preferred failover node for worker1 worker.worker1.redirect=worker2 # Define another worker using ajp13
worker.worker2.port=8009 worker.worker2.host=node2.domain.org worker.worker2.type=ajp13 worker.worker2.lbfactor=1 # Disable worker2 for all requests except failover worker.worker2.activation=disabled # Define the LB worker worker.router.type=lb worker.router.balance_workers=worker1,worker2 在worker1上的标记redirect表示仅在worker1处于问题的情况下lb_worker把请求转发给worker2。在其他情况下worker2不接受任何请求。因为这个配置看起来像hot和standby模式
Status Worker属性
# Add the status worker to the worker list worker.list=jkstatus # Define a 'jkstatus' worker using status worker.jkstatus.type=status # Add the jkstatus mount point JkMount /jkmanager/* jkstatus #使jk manager只能通过本地访问
<Location /jkmanager/> JkMount jkstatus Order deny,allow Deny from all Allow from 127.0.0.1 </Location> sticky_session:表述是否将对SESSION ID的请求路由回到相同的Tomcat worker。如果属性值不为0,它将被设置为JK_TRUE,session将是粘性的,即SESSION ID的请求路由回到相同的Tomcat worker;当Tomcat正使用能够跨越多个Tomcat实例持久化session数据的Session Manager时,它将被设置为JK_FALSE。属性默认值为JK_TRUE。 为了实现这个功能,必须修改tomcat的配置
将以前的<Engine name="Catalina" defaultHost="localhost">
修改为<Engine name="Catalina" defaultHost="localhost" jvmRoute="s1">
jvmRoute对应的worker的名称
这样,当你访问网站时,jk将请求转发给s1之后,后续的请求都是在s1上面,不会导致在s1,s2见转来转去了 Windows下整合apache+php+tomcatWindows下整合apache+php+tomcat
一、下载软件
1、 apache 2.2.11
下载地址:http://httpd.apache.org/download.cgi 文件名(示例):apache_2.2.11-win32-x86-no_ssl.msi 4、mod_jk-1.2.28
下载地址:http://tomcat.apache.org/download-connectors.cgi 文件名(示例):mod_jk-1.2.28-httpd-2.2.3.so 注意版本JK版本,必须是win32配合apache2.2的版本
二、安装软件
1.安装jdk,默认安装
2.安装apache,默认安装,使用端口80
3.安装tomat,默认安装,使用端口8080
4.将mod_jk-1.2.28-httpd-2.2.3.so拷贝到apache安装目录的modules目录下
5.将php-5.2.9-2-Win32.zip解压缩,将目录下的php.ini-dist重命名为php.ini
三、配置
1.配置apache支持php
修改apache安装目录下conf下的http.conf文件
#添加apache的php支持,注意路径名称填写正确
LoadModule php5_module "X:/php-5.2.9-2/php5apache2_2.dll" AddType application/x-httpd-php .php PHPIniDir "X:/php-5.2.9-2" #修改index文件名称支持index.php
DirectoryIndex index.html index.php 2.配置apache支持tomcat
在apache安装目录下conf下新建workers.properties文件,文件中内容如下:
worker.list=ajp13 worker.ajp13.port=9008 worker.ajp13.host=localhost worker.ajp13.type=ajp13 修改apache安装目录下conf下的http.conf文件,添加如下内容
# 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so #指定tomcat监听配置文件位置 JkWorkersFile conf/workers.properties #指定日志存放位置 JkLogFile logs/mod_jk.log JkLogLevel info #将所有jsp文件处理转发给名为ajp13的worker处理,ajp13在workers.properties文件中定义的 JkMount /*.jsp ajp13 #修改index文件名称支持index.jsp DirectoryIndex index.html index.php index.jsp 修改DocumentRoot和Directory的路径和tomcat一致,修改tomcat安装目录下conf下的server.xml
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 修改appBase和apache的一致 注意:这里容易出现的一个问题是,tomcat的appBase参数的路径下,必须有ROOT目录表示/所在的内容,apache的DocumentRoot和Directory路径要包含ROOT
示例:
apache的DocumentRoot和Directory参数:D:/Apache Software Foundation/Apache2.2/htdocs/ROOT
tomcat的appBase参数:D:\Apache Software Foundation\Apache2.2\htdocs
四、测试
启动tomcat和apache
1.在apache和tomat共同的文档目录下,新建文件test.php,内容如下: <? phpinfo(); ?> 使用http://localhost/test.php访问 2.新建文件test.jsp,内容如下: <% out.print("welcome"); %> 使用http://localhost/test.jsp访问 February 13 prototype使用ajax中文乱码的解决prototype使用ajax中文乱码的解决 一、不使用任何框架 js代码 js代码 返回正常的中文 2.jsp 如果在应用中使用filter设置了request.setCharacterEncoding("GBK"); 二、使用struts框架1.2 1.filter代码如下: public class CharacterEncodingFilter implements Filter { } public void doFilter(ServletRequest request, ServletResponse response, public void destroy() { } 2.get方式 3.post方式 关键点就在于,当使用ajax的post方式时,filter中的编码要制定utf-8,所以需要在js代码中加入requestHeaders指定RequestType为ajax已利于在filter中进行判断设置正确的编码。 注:使用prototype-1.6.0时,ajax的get方式时中文编码需要由 new String(request.getParameter("name").getBytes("iso8859-1"),"gbk") 改为: new String(request.getParameter("name").getBytes("iso8859-1"),"utf-8") post方式编码不变 转载一个最后一个字是乱码问题的解释: ajax使用utf-8 post 表单数据,而你的tomcat却认为它是gbk.... =>任意给定的3个汉字 Java代码
Java代码
Java代码
January 07 MapAbc中坐标的加密和解密MapAbc中使用编码坐标与10进度方式的坐标转换js方法,仅供参考
function getCoordinate(enLonL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[0, 8, 5, 4, 3, 9, 3, 3, 1, 3, 4, 8, 1], [1, 6, 1, 9, 4, 6, 4, 6, 4, 5, 2, 1, 5], [1, 1, 1, 6, 8, 3, 9, 1, 1, 3, 0, 9, 9], [0, 5, 1, 6, 8, 4, 8, 8, 2, 4, 4, 9, 2], [0, 2, 3, 0, 1, 4, 2, 7, 1, 9, 9, 0, 6], [0, 8, 4, 2, 5, 1, 4, 9, 5, 2, 0, 4, 3], [0, 9, 1, 2, 5, 0, 6, 6, 5, 0, 3, 1, 8], [1, 7, 8, 7, 1, 7, 4, 6, 3, 3, 3, 3, 9], [0, 3, 7, 2, 9, 4, 1, 5, 4, 7, 2, 1, 0], [1, 2, 8, 1, 1, 6, 4, 7, 8, 2, 0, 5, 2], [1, 8, 3, 5, 4, 8, 0, 9, 7, 8, 0, 1, 8], [1, 7, 9, 9, 0, 4, 5, 7, 2, 9, 0, 1, 9], [0, 6, 6, 5, 6, 7, 0, 4, 0, 7, 8, 5, 1], [0, 6, 0, 6, 3, 1, 1, 5, 0, 9, 2, 2, 3], [1, 6, 3, 5, 6, 7, 1, 6, 6, 9, 7, 4, 9], [0, 9, 5, 9, 8, 2, 4, 3, 3, 2, 3, 5, 6], [0, 1, 6, 3, 8, 9, 9, 2, 8, 2, 5, 8, 6], [1, 4, 7, 6, 6, 5, 7, 3, 3, 3, 4, 1, 1], [1, 8, 2, 9, 0, 3, 8, 6, 8, 3, 3, 7, 3], [0, 2, 8, 4, 8, 5, 4, 8, 9, 5, 0, 5, 7]]; //取编码坐标的后4位字符 var last4cha = enLonLat.substring(enLonLat.length - 4, enLonLat.length); //将后4位字符转成对应的ASCII值 var last4asc = []; for (var i = 0; i < last4cha.length; i++) { last4asc.push(last4cha.charCodeAt(i)); } //取4个数值的后两位,组成一个新的8位数字,代表key所在的索引值 var keyposition = 0; keyposition |= last4asc[0] & 3; keyposition |= (last4asc[1] & 3) << 2; keyposition |= (last4asc[2] & 3) << 4; keyposition |= (last4asc[3] & 3) << 6; //根据索引值取对应的key,key是一个长度为13的数组 var keys = __keys__[keyposition]; //取编码坐标的去掉最后4位的所有字符 var lonlat = enLonLat.substring(0, enLonLat.length - 4); //将所有字符转成对应的ASCII值 var lonlatasc = []; for (var i = 0; i < lonlat.length; i++) { lonlatasc.push(lonlat.charCodeAt(i)); } //根据key的第一位。。。 var key1 = keys[0]; var fixed = 0; switch (key1) { case 0: fixed = 23; break; case 1: fixed = 53; break; } //将所有的asc值进行处理
for (var i = 0; i < lonlatasc.length; i++) { lonlatasc[i] -= fixed; lonlatasc[i] -= keys[i + 1]; } //将处理后的asc值转成对应的asc码 var lonlatcha = []; for (var j = 0; j < lonlatasc.length; j++) { lonlatcha.push(String.fromCharCode(lonlatasc[j])); } var deLonLat = lonlatcha.join(""); return deLonLat; } //测试结果:getCoordinate("JPRLRVUSNMLHFH") 输出 116.397945
//测试结果:getCoordinate("LXJWOUOPSQVLLJL") 输出 39.90816999 October 17 IE中点击下载而不是打开文件<%
String root = getServletContext().getRealPath("/"); String path = request.getParameter("path"); String name = request.getParameter("name"); // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 response.setContentType("application/x-msdownload"); response.addHeader("Content-Disposition", "attachment;filename=\"" + name + "\""); try { java.io.OutputStream os = response.getOutputStream(); java.io.FileInputStream fis = new java.io.FileInputStream(root + path + name); byte[] b = new byte[1024]; int i = 0; while ( (i = fis.read(b)) > 0 ) { os.write(b, 0, i); } fis.close(); os.flush(); os.close(); } catch ( Exception e ) { } %> JAVA通过URL保存远程图片(转)前不久用到的,保留在此,以备查询
try { URL url = new URL( "http://images.sohu.com/uiue/sohu_logo/2005/index_logo.gif"); java.io.BufferedInputStream bis = new BufferedInputStream(url.openStream()); byte[] bytes = new byte[100]; OutputStream bos = new FileOutputStream(new File("C:\\index_logo.gif")); int len; while ( (len = bis.read(bytes)) > 0) { bos.write(bytes, 0, len); } bis.close(); bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); } September 02 MapBar中坐标的加密和解密这些天一直在使用MapBar的地图,了解了一下他所使用的地图上的编码坐标和02坐标的转换,仅供参考:
var strLicenseKey = 3409;
var c75 = 0; function zn(li, lf) { //zn把02坐标转成编码坐标 li:116.32511,lf:39.94761 var v6 = ""; // 纬度必须是大于-90小于90的值 var uh = parseInt(parseFloat(Math.max(-90, Math.min(90, lf))) * 100000); // 经度必须是大于0小于360的值,西经是负值,需要加上360 var uj = parseInt(parseFloat((li < 0) ? (li + 360) : li) * 100000); // 经度*10000 - 纬度*10000 + strLicenseKey var pl = uj - uh + parseInt(strLicenseKey); var pm = uj + uh; if (pl < 0) { v6 = "X"; pl = -pl; } if (pm < 0) { v6 = "Y"; pm = -pm; } var ph = (pl).toString(16); var pi = (pm).toString(16); //如果大于10的话加7,否则不加,然后在加10 for (var i = 0; i < ph.length; i++) { var qv = parseInt(ph.charAt(i), 16); v6 += (((qv >= 10) ? (qv + 7) : qv) + 10).toString(36); } //使用字母z分割两个参数 v6 += "z"; //如果大于10的话加7,否则不加,然后在加10 for (var qC = 0; qC < pi.length; qC++) { var S0$5 = parseInt(pi.charAt(qC), 16); v6 += (((S0$5 >= 10) ? (S0$5 + 7) : S0$5) + 10).toString(36); } //如果c75不为0,添加到最后一个这个位置的字母 if (c75) { v6 += v6.charAt(c75); } //转成大写 return v6.toUpperCase(); } function vp(xT) { //vp把编码坐标转成02坐标 xT:HEJIEIZVVHEAH var v6; var pk = -1; var fE = 0; var ub = ""; var fH = ""; if (xT != null && parseInt(xT.charAt(0), 36) >= 33) { //x=33 y=34 z=35 如果第一个字母等于X或者Y代表负号 fH = xT.charAt(0); xT = xT.substring(1); } //如果c75不为0的话,最后一个字母是c75所在位置的字母,需要去掉 for (var i = 0; i < (xT.length - (c75 ? 1 : 0)); i++) { //转成36进制后减10 var n8 = parseInt(xT.charAt(i), 36) - 10; //如果大于等于17减7 if (n8 >= 17) { n8 = n8 - 7; } //再次转为36进制 ub += (n8).toString(36); //记录最大一个值到fE中,当前位置是pk if (n8 > fE) { pk = i; fE = n8; } } //从最大一个字母截断编码,转成16进制 var n9 = parseInt(ub.substring(0, pk), 16); var n0 = parseInt(ub.substring(pk + 1), 16); if ("X" == fH) { //如果编码坐标的第一个字母是X,将n9变为负数 n9 = -n9; } if ("Y" == fH) { //如果编码坐标的第一个字母是Y,将n0变为负数 n0 = -n0; } v6 = new Array(); v6[0] = (n9 + n0 - parseInt(strLicenseKey)) / 2; v6[1] = (n0 - v6[0]) / 100000; v6[0] /= 100000; //经度大于180是西经,变成负数 if (v6[0] > 180) { v6[0] -= 360; } return v6; } 实例:
vp('HEJIEIZVVHEAH');得到结果:116.32511,39.94761
zn(116.32511,39.94761);得到结果:HEJIEIZVVHEAH August 07 JAVA解析escape编码JAVA实现解析javascript中使用escape进行编码的内容:
public class Escape {
private final static String[] hex = { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "2F", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B", "3C", "3D", "3E", "3F", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "5D", "5E", "5F", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8A", "8B", "8C", "8D", "8E", "8F", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E", "9F", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB", "AC", "AD", "AE", "AF", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF", "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB", "EC", "ED", "EE", "EF", "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF" }; private final static byte[] val = { 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F }; public static String escape(String s) {
StringBuffer sbuf = new StringBuffer(); int len = s.length(); for (int i = 0; i < len; i++) { int ch = s.charAt(i); if (ch == ' ') { // space : map to '+' sbuf.append('+'); } else if ('A' <= ch && ch <= 'Z') { // 'A'..'Z' : as it was sbuf.append((char) ch); } else if ('a' <= ch && ch <= 'z') { // 'a'..'z' : as it was sbuf.append((char) ch); } else if ('0' <= ch && ch <= '9') { // '0'..'9' : as it was sbuf.append((char) ch); } else if (ch == '-' || ch == '_' // unreserved : as it was || ch == '.' || ch == '!' || ch == '~' || ch == '*' || ch == '\'' || ch == '(' || ch == ')') { sbuf.append((char) ch); } else if (ch <= 0x007F) { // other ASCII : map to %XX sbuf.append('%'); sbuf.append(hex[ch]); } else { // unicode : map to %uXXXX sbuf.append('%'); sbuf.append('u'); sbuf.append(hex[(ch >>> 8)]); sbuf.append(hex[(0x00FF & ch)]); } } return sbuf.toString(); } public static String unescape(String s) {
StringBuffer sbuf = new StringBuffer(); int i = 0; int len = s.length(); while (i < len) { int ch = s.charAt(i); if (ch == '+') { // + : map to ' ' sbuf.append(' '); } else if ('A' <= ch && ch <= 'Z') { // 'A'..'Z' : as it was sbuf.append((char) ch); } else if ('a' <= ch && ch <= 'z') { // 'a'..'z' : as it was sbuf.append((char) ch); } else if ('0' <= ch && ch <= '9') { // '0'..'9' : as it was sbuf.append((char) ch); } else if (ch == '-' || ch == '_' // unreserved : as it was || ch == '.' || ch == '!' || ch == '~' || ch == '*' || ch == '\'' || ch == '(' || ch == ')') { sbuf.append((char) ch); } else if (ch == '%') { int cint = 0; if ('u' != s.charAt(i + 1)) { // %XX : map to ascii(XX) cint = (cint << 4) | val[s.charAt(i + 1)]; cint = (cint << 4) | val[s.charAt(i + 2)]; i += 2; } else { // %uXXXX : map to unicode(XXXX) cint = (cint << 4) | val[s.charAt(i + 2)]; cint = (cint << 4) | val[s.charAt(i + 3)]; cint = (cint << 4) | val[s.charAt(i + 4)]; cint = (cint << 4) | val[s.charAt(i + 5)]; i += 5; } sbuf.append((char) cint); } i++; } return sbuf.toString(); } public static void main(String[] args) { String stest = "中文1234 abcd[]()<+>,.~\\"; System.out.println(stest); System.out.println(escape(stest)); System.out.println(unescape(escape(stest))); } } 获取汉语拼音的JAVA实现偶然找到一个获得拼音的asp代码,发现比较短小精悍,将之改为java,以供参考
import java.util.Arrays;
import java.util.Comparator; import java.util.Hashtable; import java.util.Map; import java.util.Set; public class Dictionary {
public static String getSpellChinese(String chinese) { String spell = ""; if (chinese != null) { for (int i = 0; i < chinese.length(); i++) { short asc = 0; byte[] temp = chinese.substring(i, i + 1).getBytes(); if (temp.length == 2) { asc |= temp[0] & 0xff; asc <<= 8; asc |= temp[1] & 0xff; if (asc > -20319 && asc < -10247) { Map.Entry[] set = getSortedHashtableByKey(dictionary); for (int j = set.length - 1; j >= 0; j--) { int key = (Integer) set[j].getKey(); if (key <= asc) { spell += (String) set[j].getValue(); break; } } } } else { spell += chinese.substring(i, i + 1); } } } return spell;
} public static Hashtable dictionary = new Hashtable();
static { dictionary.put(-20319, "a"); dictionary.put(-20317, "ai"); dictionary.put(-20304, "an"); dictionary.put(-20295, "ang"); dictionary.put(-20292, "ao"); dictionary.put(-20283, "ba"); dictionary.put(-20265, "bai"); dictionary.put(-20257, "ban"); dictionary.put(-20242, "bang"); dictionary.put(-20230, "bao"); dictionary.put(-20051, "bei"); dictionary.put(-20036, "ben"); dictionary.put(-20032, "beng"); dictionary.put(-20026, "bi"); dictionary.put(-20002, "bian"); dictionary.put(-19990, "biao"); dictionary.put(-19986, "bie"); dictionary.put(-19982, "bin"); dictionary.put(-19976, "bing"); dictionary.put(-19805, "bo"); dictionary.put(-19784, "bu"); dictionary.put(-19775, "ca"); dictionary.put(-19774, "cai"); dictionary.put(-19763, "can"); dictionary.put(-19756, "cang"); dictionary.put(-19751, "cao"); dictionary.put(-19746, "ce"); dictionary.put(-19741, "ceng"); dictionary.put(-19739, "cha"); dictionary.put(-19728, "chai"); dictionary.put(-19725, "chan"); dictionary.put(-19715, "chang"); dictionary.put(-19540, "chao"); dictionary.put(-19531, "che"); dictionary.put(-19525, "chen"); dictionary.put(-19515, "cheng"); dictionary.put(-19500, "chi"); dictionary.put(-19484, "chong"); dictionary.put(-19479, "chou"); dictionary.put(-19467, "chu"); dictionary.put(-19289, "chuai"); dictionary.put(-19288, "chuan"); dictionary.put(-19281, "chuang"); dictionary.put(-19275, "chui"); dictionary.put(-19270, "chun"); dictionary.put(-19263, "chuo"); dictionary.put(-19261, "ci"); dictionary.put(-19249, "cong"); dictionary.put(-19243, "cou"); dictionary.put(-19242, "cu"); dictionary.put(-19238, "cuan"); dictionary.put(-19235, "cui"); dictionary.put(-19227, "cun"); dictionary.put(-19224, "cuo"); dictionary.put(-19218, "da"); dictionary.put(-19212, "dai"); dictionary.put(-19038, "dan"); dictionary.put(-19023, "dang"); dictionary.put(-19018, "dao"); dictionary.put(-19006, "de"); dictionary.put(-19003, "deng"); dictionary.put(-18996, "di"); dictionary.put(-18977, "dian"); dictionary.put(-18961, "diao"); dictionary.put(-18952, "die"); dictionary.put(-18783, "ding"); dictionary.put(-18774, "diu"); dictionary.put(-18773, "dong"); dictionary.put(-18763, "dou"); dictionary.put(-18756, "du"); dictionary.put(-18741, "duan"); dictionary.put(-18735, "dui"); dictionary.put(-18731, "dun"); dictionary.put(-18722, "duo"); dictionary.put(-18710, "e"); dictionary.put(-18697, "en"); dictionary.put(-18696, "er"); dictionary.put(-18526, "fa"); dictionary.put(-18518, "fan"); dictionary.put(-18501, "fang"); dictionary.put(-18490, "fei"); dictionary.put(-18478, "fen"); dictionary.put(-18463, "feng"); dictionary.put(-18448, "fo"); dictionary.put(-18447, "fou"); dictionary.put(-18446, "fu"); dictionary.put(-18239, "ga"); dictionary.put(-18237, "gai"); dictionary.put(-18231, "gan"); dictionary.put(-18220, "gang"); dictionary.put(-18211, "gao"); dictionary.put(-18201, "ge"); dictionary.put(-18184, "gei"); dictionary.put(-18183, "gen"); dictionary.put(-18181, "geng"); dictionary.put(-18012, "gong"); dictionary.put(-17997, "gou"); dictionary.put(-17988, "gu"); dictionary.put(-17970, "gua"); dictionary.put(-17964, "guai"); dictionary.put(-17961, "guan"); dictionary.put(-17950, "guang"); dictionary.put(-17947, "gui"); dictionary.put(-17931, "gun"); dictionary.put(-17928, "guo"); dictionary.put(-17922, "ha"); dictionary.put(-17759, "hai"); dictionary.put(-17752, "han"); dictionary.put(-17733, "hang"); dictionary.put(-17730, "hao"); dictionary.put(-17721, "he"); dictionary.put(-17703, "hei"); dictionary.put(-17701, "hen"); dictionary.put(-17697, "heng"); dictionary.put(-17692, "hong"); dictionary.put(-17683, "hou"); dictionary.put(-17676, "hu"); dictionary.put(-17496, "hua"); dictionary.put(-17487, "huai"); dictionary.put(-17482, "huan"); dictionary.put(-17468, "huang"); dictionary.put(-17454, "hui"); dictionary.put(-17433, "hun"); dictionary.put(-17427, "huo"); dictionary.put(-17417, "ji"); dictionary.put(-17202, "jia"); dictionary.put(-17185, "jian"); dictionary.put(-16983, "jiang"); dictionary.put(-16970, "jiao"); dictionary.put(-16942, "jie"); dictionary.put(-16915, "jin"); dictionary.put(-16733, "jing"); dictionary.put(-16708, "jiong"); dictionary.put(-16706, "jiu"); dictionary.put(-16689, "ju"); dictionary.put(-16664, "juan"); dictionary.put(-16657, "jue"); dictionary.put(-16647, "jun"); dictionary.put(-16474, "ka"); dictionary.put(-16470, "kai"); dictionary.put(-16465, "kan"); dictionary.put(-16459, "kang"); dictionary.put(-16452, "kao"); dictionary.put(-16448, "ke"); dictionary.put(-16433, "ken"); dictionary.put(-16429, "keng"); dictionary.put(-16427, "kong"); dictionary.put(-16423, "kou"); dictionary.put(-16419, "ku"); dictionary.put(-16412, "kua"); dictionary.put(-16407, "kuai"); dictionary.put(-16403, "kuan"); dictionary.put(-16401, "kuang"); dictionary.put(-16393, "kui"); dictionary.put(-16220, "kun"); dictionary.put(-16216, "kuo"); dictionary.put(-16212, "la"); dictionary.put(-16205, "lai"); dictionary.put(-16202, "lan"); dictionary.put(-16187, "lang"); dictionary.put(-16180, "lao"); dictionary.put(-16171, "le"); dictionary.put(-16169, "lei"); dictionary.put(-16158, "leng"); dictionary.put(-16155, "li"); dictionary.put(-15959, "lia"); dictionary.put(-15958, "lian"); dictionary.put(-15944, "liang"); dictionary.put(-15933, "liao"); dictionary.put(-15920, "lie"); dictionary.put(-15915, "lin"); dictionary.put(-15903, "ling"); dictionary.put(-15889, "liu"); dictionary.put(-15878, "long"); dictionary.put(-15707, "lou"); dictionary.put(-15701, "lu"); dictionary.put(-15681, "lv"); dictionary.put(-15667, "luan"); dictionary.put(-15661, "lue"); dictionary.put(-15659, "lun"); dictionary.put(-15652, "luo"); dictionary.put(-15640, "ma"); dictionary.put(-15631, "mai"); dictionary.put(-15625, "man"); dictionary.put(-15454, "mang"); dictionary.put(-15448, "mao"); dictionary.put(-15436, "me"); dictionary.put(-15435, "mei"); dictionary.put(-15419, "men"); dictionary.put(-15416, "meng"); dictionary.put(-15408, "mi"); dictionary.put(-15394, "mian"); dictionary.put(-15385, "miao"); dictionary.put(-15377, "mie"); dictionary.put(-15375, "min"); dictionary.put(-15369, "ming"); dictionary.put(-15363, "miu"); dictionary.put(-15362, "mo"); dictionary.put(-15183, "mou"); dictionary.put(-15180, "mu"); dictionary.put(-15165, "na"); dictionary.put(-15158, "nai"); dictionary.put(-15153, "nan"); dictionary.put(-15150, "nang"); dictionary.put(-15149, "nao"); dictionary.put(-15144, "ne"); dictionary.put(-15143, "nei"); dictionary.put(-15141, "nen"); dictionary.put(-15140, "neng"); dictionary.put(-15139, "ni"); dictionary.put(-15128, "nian"); dictionary.put(-15121, "niang"); dictionary.put(-15119, "niao"); dictionary.put(-15117, "nie"); dictionary.put(-15110, "nin"); dictionary.put(-15109, "ning"); dictionary.put(-14941, "niu"); dictionary.put(-14937, "nong"); dictionary.put(-14933, "nu"); dictionary.put(-14930, "nv"); dictionary.put(-14929, "nuan"); dictionary.put(-14928, "nue"); dictionary.put(-14926, "nuo"); dictionary.put(-14922, "o"); dictionary.put(-14921, "ou"); dictionary.put(-14914, "pa"); dictionary.put(-14908, "pai"); dictionary.put(-14902, "pan"); dictionary.put(-14894, "pang"); dictionary.put(-14889, "pao"); dictionary.put(-14882, "pei"); dictionary.put(-14873, "pen"); dictionary.put(-14871, "peng"); dictionary.put(-14857, "pi"); dictionary.put(-14678, "pian"); dictionary.put(-14674, "piao"); dictionary.put(-14670, "pie"); dictionary.put(-14668, "pin"); dictionary.put(-14663, "ping"); dictionary.put(-14654, "po"); dictionary.put(-14645, "pu"); dictionary.put(-14630, "qi"); dictionary.put(-14594, "qia"); dictionary.put(-14429, "qian"); dictionary.put(-14407, "qiang"); dictionary.put(-14399, "qiao"); dictionary.put(-14384, "qie"); dictionary.put(-14379, "qin"); dictionary.put(-14368, "qing"); dictionary.put(-14355, "qiong"); dictionary.put(-14353, "qiu"); dictionary.put(-14345, "qu"); dictionary.put(-14170, "quan"); dictionary.put(-14159, "que"); dictionary.put(-14151, "qun"); dictionary.put(-14149, "ran"); dictionary.put(-14145, "rang"); dictionary.put(-14140, "rao"); dictionary.put(-14137, "re"); dictionary.put(-14135, "ren"); dictionary.put(-14125, "reng"); dictionary.put(-14123, "ri"); dictionary.put(-14122, "rong"); dictionary.put(-14112, "rou"); dictionary.put(-14109, "ru"); dictionary.put(-14099, "ruan"); dictionary.put(-14097, "rui"); dictionary.put(-14094, "run"); dictionary.put(-14092, "ruo"); dictionary.put(-14090, "sa"); dictionary.put(-14087, "sai"); dictionary.put(-14083, "san"); dictionary.put(-13917, "sang"); dictionary.put(-13914, "sao"); dictionary.put(-13910, "se"); dictionary.put(-13907, "sen"); dictionary.put(-13906, "seng"); dictionary.put(-13905, "sha"); dictionary.put(-13896, "shai"); dictionary.put(-13894, "shan"); dictionary.put(-13878, "shang"); dictionary.put(-13870, "shao"); dictionary.put(-13859, "she"); dictionary.put(-13847, "shen"); dictionary.put(-13831, "sheng"); dictionary.put(-13658, "shi"); dictionary.put(-13611, "shou"); dictionary.put(-13601, "shu"); dictionary.put(-13406, "shua"); dictionary.put(-13404, "shuai"); dictionary.put(-13400, "shuan"); dictionary.put(-13398, "shuang"); dictionary.put(-13395, "shui"); dictionary.put(-13391, "shun"); dictionary.put(-13387, "shuo"); dictionary.put(-13383, "si"); dictionary.put(-13367, "song"); dictionary.put(-13359, "sou"); dictionary.put(-13356, "su"); dictionary.put(-13343, "suan"); dictionary.put(-13340, "sui"); dictionary.put(-13329, "sun"); dictionary.put(-13326, "suo"); dictionary.put(-13318, "ta"); dictionary.put(-13147, "tai"); dictionary.put(-13138, "tan"); dictionary.put(-13120, "tang"); dictionary.put(-13107, "tao"); dictionary.put(-13096, "te"); dictionary.put(-13095, "teng"); dictionary.put(-13091, "ti"); dictionary.put(-13076, "tian"); dictionary.put(-13068, "tiao"); dictionary.put(-13063, "tie"); dictionary.put(-13060, "ting"); dictionary.put(-12888, "tong"); dictionary.put(-12875, "tou"); dictionary.put(-12871, "tu"); dictionary.put(-12860, "tuan"); dictionary.put(-12858, "tui"); dictionary.put(-12852, "tun"); dictionary.put(-12849, "tuo"); dictionary.put(-12838, "wa"); dictionary.put(-12831, "wai"); dictionary.put(-12829, "wan"); dictionary.put(-12812, "wang"); dictionary.put(-12802, "wei"); dictionary.put(-12607, "wen"); dictionary.put(-12597, "weng"); dictionary.put(-12594, "wo"); dictionary.put(-12585, "wu"); dictionary.put(-12556, "xi"); dictionary.put(-12359, "xia"); dictionary.put(-12346, "xian"); dictionary.put(-12320, "xiang"); dictionary.put(-12300, "xiao"); dictionary.put(-12120, "xie"); dictionary.put(-12099, "xin"); dictionary.put(-12089, "xing"); dictionary.put(-12074, "xiong"); dictionary.put(-12067, "xiu"); dictionary.put(-12058, "xu"); dictionary.put(-12039, "xuan"); dictionary.put(-11867, "xue"); dictionary.put(-11861, "xun"); dictionary.put(-11847, "ya"); dictionary.put(-11831, "yan"); dictionary.put(-11798, "yang"); dictionary.put(-11781, "yao"); dictionary.put(-11604, "ye"); dictionary.put(-11589, "yi"); dictionary.put(-11536, "yin"); dictionary.put(-11358, "ying"); dictionary.put(-11340, "yo"); dictionary.put(-11339, "yong"); dictionary.put(-11324, "you"); dictionary.put(-11303, "yu"); dictionary.put(-11097, "yuan"); dictionary.put(-11077, "yue"); dictionary.put(-11067, "yun"); dictionary.put(-11055, "za"); dictionary.put(-11052, "zai"); dictionary.put(-11045, "zan"); dictionary.put(-11041, "zang"); dictionary.put(-11038, "zao"); dictionary.put(-11024, "ze"); dictionary.put(-11020, "zei"); dictionary.put(-11019, "zen"); dictionary.put(-11018, "zeng"); dictionary.put(-11014, "zha"); dictionary.put(-10838, "zhai"); dictionary.put(-10832, "zhan"); dictionary.put(-10815, "zhang"); dictionary.put(-10800, "zhao"); dictionary.put(-10790, "zhe"); dictionary.put(-10780, "zhen"); dictionary.put(-10764, "zheng"); dictionary.put(-10587, "zhi"); dictionary.put(-10544, "zhong"); dictionary.put(-10533, "zhou"); dictionary.put(-10519, "zhu"); dictionary.put(-10331, "zhua"); dictionary.put(-10329, "zhuai"); dictionary.put(-10328, "zhuan"); dictionary.put(-10322, "zhuang"); dictionary.put(-10315, "zhui"); dictionary.put(-10309, "zhun"); dictionary.put(-10307, "zhuo"); dictionary.put(-10296, "zi"); dictionary.put(-10281, "zong"); dictionary.put(-10274, "zou"); dictionary.put(-10270, "zu"); dictionary.put(-10262, "zuan"); dictionary.put(-10260, "zui"); dictionary.put(-10256, "zun"); dictionary.put(-10254, "zuo"); }
public static Map.Entry[] getSortedHashtableByKey(Hashtable h) {
Set set = h.entrySet(); Map.Entry[] entries = (Map.Entry[]) set.toArray(new Map.Entry[set .size()]); Arrays.sort(entries, new Comparator() { public int compare(Object arg0, Object arg1) { Object key1 = ((Map.Entry) arg0).getKey(); Object key2 = ((Map.Entry) arg1).getKey(); return ((Comparable) key1).compareTo(key2); } });
return entries;
} public static void main(String[] args) { String chinese = "安永洪"; System.out.println(getSpellChinese(chinese)); } } June 20 Ajax学习目前的项目中使用了Ajax技术,研究了一下,发现确实不错,看来以后可以大量使用了,不过对JS的要求比较高,还需要好好研究一下:)
项目中使用js库是prototype.js,1.5
关于Ajax部分操作比较简单
var url = 'mapAction.do';
var pars = 'method=search95190&city=' + city + '&key=' + escape(key) + "¤tPage=" + sPage + "&random=" + Math.random();; loading(); var myAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: showPOI, onFailure: showPOIFail, onException: showPOIException}); function showPOI(response) {
eval(response.responseText);
//.....
}
function showPOIFail() {
//.....
} function showPOIException() {
//.....
} 一种更简练的写法: var url = "";
var pars = ""; //loading代码显示查询中
var myAjax = new Ajax.Request(url,{method: 'post', requestHeaders:['RequestType','ajax'], parameters: pars, onComplete: function(response) { var result = response.responseText; },onFailure: function() { },onException: function() {
}}); JAVA中的加密和解密import java.security.InvalidKeyException; import javax.crypto.BadPaddingException; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; public class Security { public static String encrypt(String strSrc, String encName) byte[] bt = strSrc.getBytes(); // DES,DESede,Blowfish // keybyte为加密密钥,长度为24字节 // keybyte为加密密钥,长度为24字节 /** 将字节数组转换成16进制的字符串 */ /** 将16进制的字符串转换成字节数组 */ return bytes; public static void main(String[] args) { messageDigest.update(originalPwd.getBytes()); // 转换成Base64编码保存 // 转换成16进制字符串保存 // System.out.println("encrypt:" + encrypt(originalPwd, "MD5")); //实际使用中,遇到了与C语言写的3DES加解密结果不一致的情况,经过调试,发现它使用的是16位的密码,在java中的密钥是24位,后8位不能自动补0而应该是前八位的内容,在使用模式ECB/NOPadding时,源串长度必须是8的整数倍,不足部分补0,所以会报告错误。看来,什么东西只掌握一个皮毛是不行的啊 /** ********************************************************* */ byte[] keybyte = new byte[24]; int ileft = (srcbyte.length) % (8); } February 18 使用Log4j无法找到日志文件的问题问题:
在使用Log4j生成日志文件时,发生
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: \logs\log.txt (系统找不到指定的路径。) 而在WEB-INF目录下已经存在logs目录了。 原因:
经查,是common.logging产生的的错误,因为common.logging日志无需配置,只要WEB-INF/classes目录下有它可以解析的文件格式,就会被common.logging作为它的配置文件,也就是说它把log4j的配置文件作为common.logging配置文件初始化了。
解决:
1.将common-logging包从WEB-INF/lib目录下删除,删除之前请确认你的系统中没有用该包。(已验证过)
2.将LOG4J的配置文件不要放在classess目录下(未验证)。 January 30 使用Jakarta Comons-Email简化JavaMail在http://commons.apache.org/email/下载commons-email.jar目前是1.1版本
1.通过SimpleEmail发送邮件
SimpleEmail email = new SimpleEmail(); email.setHostName("mail.163.com"); email.setAuthentication("<username>","<password>") email.addTo(xxx@163.com, "xxx"); email.setFrom(xxx@163.cn, "xxx"); email.setSubject("测试主题"); email.setCharset("UTF-8"); email.setMsg("这里是邮件内容"); email.send(); 注意问题:不设置编码的话,可能会出现???的乱码 2.发送带附件的邮件
MultiPartEmail email = new MultiPartEmail(); email.setHostName("mail.163.com"); email.setAuthentication("<username>","<password>") email.addTo(xxx@163.com, "xxx"); email.setFrom(xxx@163.cn, "xxx"); email.setSubject("测试主题"); email.setCharset("UTF-8"); email.setMsg("这里是邮件内容"); //发送本地附件 EmailAttachment attachment = new EmailAttachment(); attachment.setPath("x:\\xxx.txt"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("xxx"); email.attach(attachment); //发送不存在本地的附件 EmailAttachment attachment1 = new EmailAttachment(); attachment1.setURL(new URL("http://xxx.xxx.xxx/xxx.jpg")); attachment1.setDisposition(EmailAttachment.ATTACHMENT); attachment1.setDescription("xxx"); email.attach(attachment1); email.send(); 3.发送html格式的邮件 HtmlEmail email = new HtmlEmail(); email.setHostName("mail.163.com"); email.setAuthentication("<username>","<password>") email.addTo(xxx@163.com, "xxx"); email.setFrom(xxx@163.cn, "xxx"); email.setSubject("该邮件包括html格式内容"); email.setCharset("UTF-8"); email.setMsg("这里是邮件内容"); email.setHtmlMsg("<html><head><title>test</title></head><body><font color='red'>中文</font></body></html>"); email.setTextMsg("Your email client does not support HTML messages"); email.send(); 注意问题:html格式邮件可以发送附件,和上面相同 January 29 JavaMail无法连接SMTP25端口问题测试JavaMail发邮件功能,始终发生错误:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.163.com, port: 25
使用outlook收发邮件正常,使用telnet smtp.163.com 25不能连接
什么错误?很是莫名其妙!
从网上查资料,只有提问的没有回答的,有些都问了若干年了没有答案,真年头技术都在干嘛啊?
废话少说,问题查到了,是安装的杀毒软件进行了端口拦截,“禁止大量发送邮件的蠕虫病毒发送邮件端口25”,outlook之所以能够使用是因为outlook的进程被加到“已排除进程”中。反垃圾邮件功能阻止了javaw.exe和telenet.exe对port 25的访问!
取消掉对javaw.exe、java.exe和telenet.exe的阻止,telnet成功,发送邮件成功!
备注:找到一个发送邮件的简单的方式,使用apache commons email,简单实用,开源就是好啊^-^ Linux下Tomcat不能使用80端口问题在Linux下低于1024的端口是root专用,而Tomcat安装后默认使用用户tomcat启动的,所以将端口改为80后启动,会产生错误:java.net.BindException: Permission denied:80 解决方法1: 重将Tomcat的端口改为8080 然后:iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 解决方法2: 使用root启动Tomcat,或者将Tomcat启动时的配置文件中的用户tomcat改为root |
|
|