jsp程序能够正常运行但点击按钮后没有反应
代码如下:
data.java:
package com.jgj.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Hashtable;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class data extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Hashtable<String, String[]> ht = new Hashtable<String, String[]>();
ht.put("1", new String[] { "清河区房屋", "清河区", "2室2厅", "2", "80", "60" });
ht.put("2", new String[] { "清浦区房屋", "清浦区", "2室2厅", "2", "80", "60" });
ht.put("3", new String[] { "淮阴区房屋", "淮阴区", "2室2厅", "2", "80", "60" });
ht.put("4", new String[] { "开发区房屋", "开发区", "2室2厅", "2", "80", "60" });
response.setContentType("text/JSON;charset=utf-8");
response.setCharacterEncoding("utf-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
String districtid = request.getParameter("qxid");
String[] result = ht.get(districtid);
StringBuffer sb = new StringBuffer();
sb .append("<table><tr><td>房屋名称</td><td>所在区县</td><td>房型</td><td>楼层</td><td>面积</td><td>价格</td></tr>");
sb.append("<tr><td>" + result[0] + "</td>");
sb.append("<td>" + result[1] + "</td>");
sb.append("<td>" + result[2] + "</td>");
sb.append("<td>" + result[3] + "</td>");
sb.append("<td>" + result[4] + "</td>");
sb.append("<td>" + result[5] + "</td></tr>");
sb.append("</table>");
out.print(sb.toString());
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
search.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#search").click(function()
{
$.post("data",{qxid:$("#qxid").val()},function(data)
{
$("#result").empty();
$("#result").append(data);
});
});
});
</script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<div align="center"> <form >
<label> <p>选择房屋所在区县:</p>
<select id="qxid">
<option value="1">清河区</option>
<option value="2">清浦区</option>
<option value="3">淮阴区</option>
<option value="4">开发区</option> </select>
</label>
<button id="search" >开始查询</button> </form>
</div>
<div id="result" align="center"></div>
</body>
</html>