JSON.stringify(opt) //创建json对象
js正则:
/^\d{0,11}$/.test(phoneNum);
jquery ajax:
function post(_url, param, callback){
$.ajax({
type: "POST",
url: _url,
dataType: "html",
contentType: "application/x-www-form-urlencoded",
data: "cmdStr=" + JSON.stringify(param),
success: callback,
error: errCallback,
async: false
});
};
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>//jstl标签
eclipse下面需要配置web.xml
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
1、DOM对象转jQuery对象
普通的Dom对象一般可以通过$()转换成jQuery对象。
如:$(document.getElementById("msg"))
返回的就是jQuery对象,可以使用jQuery的方法。
2、jQuery对象转DOM对象
由于jQuery对象本身是一个集合。所以如果jQuery对象要转换为Dom对象则必须取出其中的某一项,一般
可通过索引取出。
如: $("#msg")[0],$("div").eq(1)[0],$("div").get()[1],$("td")[5]
这些都是Dom对象,可以使用Dom中的方法,但不能再使用jQuery的方法。
以下几种写法都是正确的:
$("#msg").html();
$("#msg")[0].innerHTML;
$("#msg").eq(0)[0].innerHTML;
$("#msg").get(0).innerHTML;
//编码问题
UTF-8的bom头
何谓BOM? "EF BB BF" 这三个字节就叫BOM,BOM的全称叫做"Byte Order Mard".在utf-8文件中常用
BOM来表明这个文件是UTF-8文件,而BOM的本意实在utf16中用来表示高低字节序列的。在字节流之前有
BOM表示采用低字节序列(低字节在前面),而utf8不用考虑字节序列,所以其实有无BOM都可以。UTF-8
以字节为编码单元,没有字节序的问题。 UTF-16以两个字节为编码单元,在解释一个UTF-16文本前,首
先要弄清楚每个编码单元的字节序。例如收到一个“奎”的Unicode编码是 594E,“乙”的Unicode编码
是4E59。如果我们收到UTF-16字节流“594E”,那么这是 “奎”还是“乙”?
//restFul实现json与类的转换
request.getTypedParameter("person", Person.class);
//js字符串转换成json,ajax使用
var s='{"name":"kkk"}';
var sj='var jsonobj='+s;
eval(sj);
alert(jsonobj.name);
弹出层
var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.style.background="white";
msgObj.style.border="1px solid #0000FF";
msgObj.style.position = "absolute";
msgObj.style.width = 300 + "px";
msgObj.style.height =120 + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.visibility = 'visible';
msgObj.style.zIndex = "10001";
//日记
private static final Logger logger = Logger.getLogger(
AuthenticationServletFilter.class);
/**
* @param url
* @return
* @throws Exception
*/
static String httpGet(String url) throws Exception{
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(Config.SNS_URL+url);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new Exception(method.getStatusLine().toString());
}
InputStream ins = method.getResponseBodyAsStream();
// 按指定的字符集构建文件流
BufferedReader br = new BufferedReader(new
InputStreamReader(ins,
"utf-8"));
StringBuffer sbf = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sbf.append(line);
}
/** 回收资源 */
br.close();
return br.toString();
// Read the response body.
// byte[] responseBody = method.getResponseBody();
//
// // Deal with the response.
// // Use caution: ensure correct character encoding and is not binary
data
// //System.out.println(new String(responseBody));
// return new String(responseBody);
} finally {
// Release the connection.
method.releaseConnection();
}
}
/**
* @param cmd
* @return
* @throws Exception
*/
static String httpSend(CmdStr cmd) throws Exception{
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf
-8");
PostMethod method = new PostMethod(Config.URLMAP.get(cmd.getCmd()));
NameValuePair[] data = {
new NameValuePair("cmdStr", JsonSerializer.serialize(cmd))
};
method.setRequestBody(data);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new Exception(method.getStatusLine().toString());
}
// Read the response body.
// byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary
data
//System.out.println(new String(responseBody));
InputStream ins = method.getResponseBodyAsStream();
// 按指定的字符集构建文件流
BufferedReader br = new BufferedReader(new
InputStreamReader(ins,
"utf-8"));
StringBuffer sbf = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sbf.append(line);
}
/** 回收资源 */
br.close();
// responseStr = postMethod.getResponseBodyAsString();
//return new String(responseBody);
return sbf.toString();
} finally {
// Release the connection.
method.releaseConnection();
}
}
js正则:
/^\d{0,11}$/.test(phoneNum);
jquery ajax:
function post(_url, param, callback){
$.ajax({
type: "POST",
url: _url,
dataType: "html",
contentType: "application/x-www-form-urlencoded",
data: "cmdStr=" + JSON.stringify(param),
success: callback,
error: errCallback,
async: false
});
};
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>//jstl标签
eclipse下面需要配置web.xml
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
1、DOM对象转jQuery对象
普通的Dom对象一般可以通过$()转换成jQuery对象。
如:$(document.getElementById("msg"))
返回的就是jQuery对象,可以使用jQuery的方法。
2、jQuery对象转DOM对象
由于jQuery对象本身是一个集合。所以如果jQuery对象要转换为Dom对象则必须取出其中的某一项,一般
可通过索引取出。
如: $("#msg")[0],$("div").eq(1)[0],$("div").get()[1],$("td")[5]
这些都是Dom对象,可以使用Dom中的方法,但不能再使用jQuery的方法。
以下几种写法都是正确的:
$("#msg").html();
$("#msg")[0].innerHTML;
$("#msg").eq(0)[0].innerHTML;
$("#msg").get(0).innerHTML;
//编码问题
UTF-8的bom头
何谓BOM? "EF BB BF" 这三个字节就叫BOM,BOM的全称叫做"Byte Order Mard".在utf-8文件中常用
BOM来表明这个文件是UTF-8文件,而BOM的本意实在utf16中用来表示高低字节序列的。在字节流之前有
BOM表示采用低字节序列(低字节在前面),而utf8不用考虑字节序列,所以其实有无BOM都可以。UTF-8
以字节为编码单元,没有字节序的问题。 UTF-16以两个字节为编码单元,在解释一个UTF-16文本前,首
先要弄清楚每个编码单元的字节序。例如收到一个“奎”的Unicode编码是 594E,“乙”的Unicode编码
是4E59。如果我们收到UTF-16字节流“594E”,那么这是 “奎”还是“乙”?
//restFul实现json与类的转换
request.getTypedParameter("person", Person.class);
//js字符串转换成json,ajax使用
var s='{"name":"kkk"}';
var sj='var jsonobj='+s;
eval(sj);
alert(jsonobj.name);
弹出层
var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.style.background="white";
msgObj.style.border="1px solid #0000FF";
msgObj.style.position = "absolute";
msgObj.style.width = 300 + "px";
msgObj.style.height =120 + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.visibility = 'visible';
msgObj.style.zIndex = "10001";
//日记
private static final Logger logger = Logger.getLogger(
AuthenticationServletFilter.class);
/**
* @param url
* @return
* @throws Exception
*/
static String httpGet(String url) throws Exception{
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(Config.SNS_URL+url);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new Exception(method.getStatusLine().toString());
}
InputStream ins = method.getResponseBodyAsStream();
// 按指定的字符集构建文件流
BufferedReader br = new BufferedReader(new
InputStreamReader(ins,
"utf-8"));
StringBuffer sbf = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sbf.append(line);
}
/** 回收资源 */
br.close();
return br.toString();
// Read the response body.
// byte[] responseBody = method.getResponseBody();
//
// // Deal with the response.
// // Use caution: ensure correct character encoding and is not binary
data
// //System.out.println(new String(responseBody));
// return new String(responseBody);
} finally {
// Release the connection.
method.releaseConnection();
}
}
/**
* @param cmd
* @return
* @throws Exception
*/
static String httpSend(CmdStr cmd) throws Exception{
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf
-8");
PostMethod method = new PostMethod(Config.URLMAP.get(cmd.getCmd()));
NameValuePair[] data = {
new NameValuePair("cmdStr", JsonSerializer.serialize(cmd))
};
method.setRequestBody(data);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
try {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new Exception(method.getStatusLine().toString());
}
// Read the response body.
// byte[] responseBody = method.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary
data
//System.out.println(new String(responseBody));
InputStream ins = method.getResponseBodyAsStream();
// 按指定的字符集构建文件流
BufferedReader br = new BufferedReader(new
InputStreamReader(ins,
"utf-8"));
StringBuffer sbf = new StringBuffer();
String line = null;
while ((line = br.readLine()) != null) {
sbf.append(line);
}
/** 回收资源 */
br.close();
// responseStr = postMethod.getResponseBodyAsString();
//return new String(responseBody);
return sbf.toString();
} finally {
// Release the connection.
method.releaseConnection();
}
}