ajax的Servlet进不去
アナリスト 2012-10-24 12:43:35 ajax的Servlet进不去是怎么回事,配置没有问题的,之前进去过的。
js代码如下:
<script language="javascript" type="text/javascript">
var xmlHttp;
var rowc=0;
function createXMLHttp(){
if(window.XMLHttpRequest){
xmlHttp= new XMLHttpRequest() ;
} else {
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP") ;
}
}
function enterfun()
{
createXMLHttp() ;
xmlHttp1.open("POST","Select_orderServlet?usr_tel="+<%= (String)session.getAttribute("zhanghao")%>);
xmlHttp1.onreadystatechange = checkUseridCallback;
xmlHttp1.send(null) ;
}
function checkUseridCallback(){
alert(xmlHttp.readyState+" "+xmlHttp1.status);
if(xmlHttp1.readyState == 4){
if(xmlHttp1.status == 200){
var text = xmlHttp.responseText ;
alert(text);
}
}
}
</script>
Select_orderServlet.java的doPost函数代码如下:
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
request.setCharacterEncoding("utf-8") ;
response.setContentType("text/html") ;
System.out.println("****************我进去了**************");//后台没输出这句话!!!!!!没进去啊!!!!
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
PrintWriter out = response.getWriter() ;
String usr_tel= request.getParameter("usr_tel");
int orderid=0;
float order_totalprice=0;
Timestamp order_time=null;
int order_item_id=0;
int product_id=0;
int quantity=0;
float unitprice=0;
String size=null;
String style=null;
String mianliao=null;
try
{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
String sql = "select * from order_of_usr where usr_tel=?" ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,usr_tel) ;
rs=pstmt.executeQuery() ;
while(rs.next())
{
orderid=rs.getInt(1);
order_totalprice=rs.getFloat(3);
order_time=rs.getTimestamp(4);
//System.out.println(orderid+" "+order_totalprice+" "+order_time);
out.print(orderid+","+order_totalprice+","+order_time+",");//本该得到的内容
}
sql = "select * from order_item where order_id=?" ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setInt(1,orderid) ;
rs=pstmt.executeQuery() ;
while(rs.next())
{
order_item_id=rs.getInt(1);
product_id=rs.getInt(3);
size=rs.getString(4);
style=rs.getString(5);
mianliao=rs.getString(6);
quantity=rs.getInt(7);
unitprice=rs.getFloat(8);
System.out.println(size+","+style+","+mianliao+","+quantity+",");
out.print(size+","+style+","+mianliao+","+quantity+",");//本该得到的内容
}
//System.out.println("*******************");
}catch(Exception e){
e.printStackTrace() ;
}finally{
try{
out.close();
conn.close() ;
pstmt.close();
}catch(Exception e){}
}
}
最后alert(text);得到的是一整个html代码,也不知道哪来的。在线等!!!