读书人

Ajax入门事例

发布时间: 2012-10-28 09:54:44 作者: rapoo

Ajax入门例子

index.jsp

?

struts_config.xml

?

TempAction.java

@Overridepublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {PrintWriter pw = response.getWriter();SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");String today = df.format(new Date());//(1)这里的print就是index.jsp中要获取的responseTextpw.print(today);//(2)记得要flushpw.flush();//(3)如果是ajax的请求,这里不要返回页面,不然会将整个页面html源码赋值到responseText中return null;}
?

读书人网 >Ajax

热点推荐