当前位置: 代码迷 >> Ajax >> jquery中ajax跟java的结合
  详细解决方案

jquery中ajax跟java的结合

热度:561   发布时间:2012-10-14 14:55:07.0
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"));
		}

	}

  相关解决方案