jsp程序能够正常运行但点击按钮后没有反应

qq_22100063 2015-06-03 06:13:38
代码如下:
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>
...全文
636 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
枫醉秋 2015-06-04
  • 打赏
  • 举报
回复
<script type="text/javascript"> $(document).ready(function() { $("#search").click(function() { $.post(“提交的地址”,"data",{qxid:$("#qxid").val()},function(data) { $("#result").empty(); $("#result").append(data); }); }); }); </script>
qq_22100063 2015-06-04
  • 打赏
  • 举报
回复
引用 3 楼 sdl1314520 的回复:
已经有了form表单,直接这样 <form action=“路径” method=“get”>
加这句就可以了吗?才开始学java,能解释的详细点吗?
枫醉秋 2015-06-04
  • 打赏
  • 举报
回复
都没有提交的url,肯定进不了后台的,追加要提交的地址吧
sdl1314520 2015-06-04
  • 打赏
  • 举报
回复
已经有了form表单,直接这样 <form action=“路径” method=“get”>
sdl1314520 2015-06-04
  • 打赏
  • 举报
回复
你用的是post提交,后台接收的确实doget(),肯定不行啊
泪的告白篇 2015-06-03
  • 打赏
  • 举报
回复
会用浏览器调试js吗?

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧