Loading...

Category Archives: All post.  | - 查看最近留言- |   | - 详细分类查看TAGS - |

JQUERY.AJAX访问XML的问题.

不是直接.ajax访问.XML后缀的文件,而是访问对数据进行简单的封装了的xml字符串(对于一般复杂结构数据的传输,像查询出的记录)~比如我下面这段用dom4j生成的XML字符串。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Response.setContentType("text/html;charset=UTF-8");
 
PrintWriter writer = Response.getWriter();
String PK_ID = Request.getParameter("selectxmmc");
 
Connection connection = null;
PreparedStatement statementQuery = null;
Document doc = DocumentHelper.createDocument();
 
try {
	connection = DatabaseHelper.getConnection(componentManager);
	statementQuery = connection
			.prepareStatement("select * from oa_sdsl_ss_xm where PK_ID = ?");
	statementQuery.setString(1, PK_ID);
	ResultSet rs = statementQuery.executeQuery();
	Element root = doc.addElement("root");
	while (rs.next()) {
		Element xm = root.addElement("xm");
		Element dd = xm.addElement("dd");
		dd.addText(rs.getString("xmdd"));
		Element xmfr = xm.addElement("xmfr");
		xmfr.addText(rs.getString("xmfr"));
		Element jsdw = xm.addElement("jsdw");
		jsdw.addText(rs.getString("jsdw"));
	}
	rs.close();
 
	statementQuery.close();
	statementQuery = null;
	connection.commit();
	connection.close();
	connection = null;
 
	writer.print(doc.asXML());
	writer.close();
 
} catch (Exception ex) {
	ex.printStackTrace();
	writer.print("error");
	writer.close();
} finally {
	if (statementQuery != null) {
		try {
			statementQuery.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}
	if (connection != null) {
		try {
			connection.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}
}

继续阅读…Continue Reading » » »

Posted 06 八月 2008 GLLL.§Diary评论(0)± Tags: + +  

关于Servlet接收Form参数乱码.

JQuery在JAVA中表现还是不错的,这是我在现在的项目中遇到的,可能是由于JQuery.AJAX使用UTF8传递参数而公司是GB2312(个人感觉 - - GB2312页面,但是.AJAX的时候UTF8传递,SERVLET接收UTF8参数乱码。 )?
如果是DWR实现通过配置便可以解决这样的问题,如果接收和表单页面是PHP和JSP我想直接把它存成UTF8也可解决,不过公司是纯JAVA的系统,表单等是直接存入数据库后由一底层的servlet writer.print();出来。当然不会为了一两个JQuery相关的页面而去改底层的东西。

顺便再介绍一下这个JFORM插件,JQUERY AJAX提交表单的非常好用的插件(转一下翻译后的API):

一般我们最常用的方法就是(jform是需要提交的表单ID):

1
2
3
4
5
6
7
8
9
10
jQuery("#jform").ajaxSubmit({
	url : "url",
	type : "post",
	success : function(result) {
		alert(result);
	},
	error : function() {
		alert("error");
	}
});

继续阅读…Continue Reading » » »

Posted 01 八月 2008 GLLL.§Diary评论(1)± Tags: + + +