jquery+ajax异步请求没得响应,后台也进了求大神看看spring+spring MVC+mybatis做的

jl13972236494 2014-05-09 04:55:17
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>js/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/uploadify/jquery.uploadify.js"></script>
<script type="text/javascript">
var i;
function clicks(id){
$.ajax({
type:"post",
contentType: "application/json",
processData : true,
dataType: "text",
url:"<%=basePath%>getHomeById.html?homeId="+id,
success:function(result){
alert(result);
/* var jsonObj = eval('('+result+')');
$("#display").css("display","block");
$("#homeId").val(jsonObj.homeId);
$("#homeName").val(jsonObj.homeName);
$("#homeAddress").val(jsonObj.homeAddress);
$("#homePrice").val(jsonObj.homePrice); */
}
});
}
$(document).ready(function(){
var div=document.getElementById("div");
var span=document.getElementById("span");
span.style.marginLeft="100px";
div.style.marginLeft="700px";
div.style.marginTop="20px";
});
</script>
</head>
<body>
<div id="div">
<span id="span">
${user.uname }:欢迎光临。。。
</span>
<table cellpadding="5" cellspacing="0" border="1">
<tr>
<th>房屋名称</th>
<th>房屋地址</th>
<th>房屋价格</th>
<th width="100">发布时间</th>
<th width="100">操作</th>
</tr>
<c:forEach var="list" items="${list }">
<tr align="center">
<td>${list.homeName }</td>
<td>${list.homeAddress }</td>
<td>${list.homePrice }</td>
<td>${list.homeTime }</td>
<td>
<a href="deleteHome.html?homeId=${list.homeId}">删除</a> ||
<input type="hidden" value="${list.homeId }"/>
<a href="showHome.html?homeId=${list.homeId }" id="${list.homeId }" <%-- onclick='clicks(${list.homeId})' --%>>修改</a></td>
</tr>
</c:forEach>
</table>
<form action="updateHome.html" method="post">
<table cellpadding="5" cellspacing="0" border="1">
<tr>
<th>房屋名称</th>
<th>房屋地址</th>
<th>房屋价格</th>
<th width="100">发布时间</th>
<th width="100">操作</th>
</tr>
<tr>
<td><input type="text" name="homeName" size="9" value="${home.homeName }"/></td>
<td><input type="text" name="homeAddress" size="9" value="${home.homeAddress }"/></td>
<td><input type="text" name="homePrice"size="9" value="${home.homePrice }"/></td>
<td>
<fmt:formatDate value="${home.homeTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
</td>
<td>
<input type="hidden" name="homeId" value="${home.homeId }"/>
<input type="submit" name="Submit" value="确定修改"/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>



@RequestMapping("getHomeById")
@ResponseBody
public void getHomeById(Home home,HttpServletRequest request,HttpServletResponse response){
Home h=homeServlet.getHomeById(home.getHomeId());
try {
response.getWriter().print(h);
} catch (IOException e) {
e.printStackTrace();
}
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>backgroundSupervise</display-name>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/dispatcherServlet-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<!-- 日志配置
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j.properties</param-value>
</context-param> -->

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/applicationContext.xml</param-value>
</context-param>

<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>

</filter>

<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<!-- JDBC配置 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/config/jdbc.properties</value>
</property>
</bean>


<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true" />
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}" />
<property name="initialPoolSize" value="${cpool.minPoolSize}" />
<property name="minPoolSize" value="${cpool.minPoolSize}" />
<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
</bean>

<!-- sqlSessionFactory -->
<bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 设置数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 设置映射器XML文件路径自动加载 -->
<property name="mapperLocations" value="classpath*:com/scce/**/*.xml" />
<!-- 设置总配置 -->
<property name="configLocation" value="/WEB-INF/config/mybatis-config.xml"></property>
</bean>

<!-- 设置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 扫描Mapper接口交给Spring管理 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.scce.mapper" />
</bean>

</beans>


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd ">

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>

<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.scce" />

</beans>

我的页面修改那里有注释要看清楚哟
...全文
179 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jl13972236494 2014-05-09
  • 打赏
  • 举报
回复
没又发现问题所在
tony4geek 2014-05-09
  • 打赏
  • 举报
回复
修改了。可以了?
jl13972236494 2014-05-09
  • 打赏
  • 举报
回复
@RequestMapping("getHomeById") @ResponseBody public void getHomeById(Home home,HttpServletRequest request,HttpServletResponse response){ Home h=homeServlet.getHomeById(home.getHomeId()); try { response.getWriter().print(h); } catch (IOException e) { e.printStackTrace(); } } 后台赋值错了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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