日期:2014-05-16  浏览次数:20618 次

jquery中ajax和java的结合
	$.ajax({								type: "post",
		url: "<session:constant name='ContextPath'/>/dataSvc/createDataSvcOnLoad.do",
		dataType: "xml",
		complete: function(data, textStatus) {
			alert("complete"); 
		          },
		error: function(){
			alert("error");
			},						success: function(data, textStatus) {
			alert("success"); 
			}
		});


public void comnamd(CommandContext<String, Object> input){
HttpServletRequest req = ((ServletCommandContext<String, Object>) input).getRequest();
String content = loadFormTemplet(folderPath + File.separator + fileName + ".xml");
addResponseMessage(resp, content);
}

private void addResponseMessage(HttpServletResponse resp, String message)
			throws PFCommandException {
		try {
			resp.setContentType("text/xml;charset=UTF-8");
			resp.setHeader("Cache-Control", "no-cache");
			PrintWriter out = resp.getWriter();
			out.print(message);
			out.flush();
			out.close();
		} catch (IOException e) {
			throw new PFCommandException(new Message(
					"msg.form.response.message.error"));
		}

	}