JS异步请求数据

 

不刷新页面,不需要Jquery等等

 

JS代码

var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open("Get","demo.do?status=c&name="+name,false);
http.send();
alert(http.responseText);

 Java代码

public class DemoAction
    extends DispatchAction {

     public ActionForward c(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception {
     String name= new String(request.getParameter("name").getBytes("ISO-8859-1"), "gbk");

    request.setAttribute("ch","aaa");
    return (mapping.findForward("ch"));
  }
}
 
struts.xml
  <action type="com.DemoAction" parameter="status" path="/demo" >
    <forward name="ch" path="/ch.jsp" />
  </action>

 

ch.jsp代码

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><%String ch=(String)request.getAttribute("ch");

 

 

 

 

 

 

 

posted @ 2012-07-25 17:30  飝兒  阅读(6426)  评论(0编辑  收藏  举报