- 浏览: 2493 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
WEB.XML
application-mvc.xml
application.xml
UserModel.java
DemoController.java
index.jsp
index.js
运行结果如下图所示,
使用Chrome调试时,提示信息如下:
Resource interpreted as Document but transferred with MIME type application/json.
还没有找到解决办法,嘿嘿
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>RFADispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:springcfg/applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>RFADispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- 工程编码过滤器 --> <filter> <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
application-mvc.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <import resource="applicationContext.xml"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;UTF-8</value> </list> </property> </bean> </list> </property> </bean> <bean name="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" /> <!-- enable component scanning (beware that this does not enable mapper scanning!) --> <context:component-scan base-package="com.das.casit.rfa.controller.speed"> <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect" /> </context:component-scan> <mvc:annotation-driven/> <!-- enable autowire --> <context:annotation-config /> <!-- enable transaction demarcation with annotations --> <tx:annotation-driven /> <!-- 跳转视图配置 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 设置全局异常处理方式。!注意,如果使用XML配置了异常处理方式, 那么使用Annotation处理异常的方式将不再被使用。 --> <bean name="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <!-- 这里的errorPage同样应用viewResolver的前缀、后缀匹配 --> <prop key="java.lang.Exception">errorPage</prop> </props> </property> </bean> </beans>
application.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"> <import resource="applicationContext-bean.xml"/> <!-- ============================== 数据库配置 ==================================== --> <!-- 数据源配置 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value> </property> <property name="url"> <value>jdbc:sqlserver://localhost:1433;DatabaseName=ihToSql;SelectMethod=cursor</value> </property> <property name="username"> <value>hydas</value> </property> <property name="password"> <value>!Hcf@2009</value> </property> </bean> <!-- ================================= 事务控制相关 ============================================= --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- ================================ MyBatis SqlSession配置 ========================================= --> <!-- 使用SqlSessionFactoryBean工厂产生SqlSession对象,方便后期注入Dao --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:myBatiscfg/Configuration.xml"></property> </bean> </beans>
UserModel.java
package com.das.casit.rfa.controller.speed; /** * @author Administrator * */ public class UserModel { private String id; private String username; private int age; /** * @return the id */ public String getId() { return id; } /** * @param id the id to set */ public void setId(String id) { this.id = id; } /** * @return the username */ public String getUsername() { return username; } /** * @param username the username to set */ public void setUsername(String username) { this.username = username; } /** * @return the age */ public int getAge() { return age; } /** * @param age the age to set */ public void setAge(int age) { this.age = age; } }
DemoController.java
/** * */ package com.das.casit.rfa.controller.speed; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/speed") public class DemoController { private Logger logger = LoggerFactory.getLogger(DemoController.class); @RequestMapping(value = "/list", method = RequestMethod.GET) @ResponseBody public Map<String, Object> getUserList() { logger.info("�б�"); List<UserModel> list = new ArrayList<UserModel>(); UserModel um = new UserModel(); um.setId("1"); um.setUsername("sss"); um.setAge(222); list.add(um); Map<String, Object> modelMap = new HashMap<String, Object>(3); modelMap.put("total", "1"); modelMap.put("data", list); modelMap.put("success", "true"); return modelMap; } @RequestMapping(value = "/add", method = RequestMethod.POST) @ResponseBody public Map<String, String> addUser(@RequestBody UserModel model) { Map<String, String> map = new HashMap<String, String>(1); map.put("success", "true"); return map; } }
index.jsp
<?xml version="1.0" encoding="UTF-8" ?> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Script-Type" content="text/html; charset=UTF-8" /> <title>Spring MVC</title> <script src="../jsLib/jqGrid/js/jquery-1.5.2.min.js" type="text/javascript"></script> <script src="../jsLib/jqGrid/js/i18n/grid.locale-cn.js" type="text/javascript"></script> <script src="../jsLib/jqGrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> <script type="text/javascript" src="index.js"></script> </head> <body> <div id="info"></div> <form action="add" method="post" id="form"> 编号:<input type="text" name="id"/> 姓名:<input type="text" name="username"/> 年龄:<input type="text" name="age"/> <input type="button" value="提交" id="submit"/> </form> </body> </html>
index.js
$.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [ o[this.name] ]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }; $(document).ready( function() { alert("here"); jQuery.ajax( { type : 'GET', contentType : 'application/json', url : 'user/list', dataType : 'json', success : function(data) { if (data && data.success == "true") { $('#info').html("共" + data.total + "条数据。<br/>"); $.each(data.data, function(i, item) { $('#info').append( "编号:" + item.id + ",姓名:" + item.username + ",年龄:" + item.age); }); } }, error : function() { alert("error") } }); $("#submit").click(function() { var jsonuserinfo = $.toJSON($('#form').serializeObject()); alert(jsonuserinfo); jQuery.ajax( { type : 'POST', contentType : 'application/json', url : 'user/add', data : jsonuserinfo, dataType : 'json', success : function(data) { alert("新增成功!"); }, error : function(data) { alert("error") } }); }); });
运行结果如下图所示,
![](http://dl.iteye.com/upload/attachment/491991/6d1ebf41-96de-35f1-82d9-a5b15f62894d.jpg)
使用Chrome调试时,提示信息如下:
Resource interpreted as Document but transferred with MIME type application/json.
还没有找到解决办法,嘿嘿
相关推荐
Spring MVC 分页组件和JqGrid导出 分页组件为通用 比较全面 jqGrid 实现导出excel功能 及行添加按钮操作
在mvc 中 应用 jqgrid技术,一个在mvc中应用 最广泛的表格插件。
##Fontus Spring MVC & jqGrid:一个 CRUD 应用程序样板###介绍该项目是 CRUD Web 应用程序的模板/演示。 它使用 Spring Web MVC(一种 Java Web 框架)和 jqGrid(一种开源 JavaScript 网格)。 该应用程序具有...
实例讲解在ASP.NET MVC模式通过jQgrid表格操作 文章来自学IT网:http://www.xueit.com/asp.net/show-9768-3.aspx实例讲解在ASP.NET MVC模式通过jQgrid表格操作 文章来自学IT网:...
ASP.NET MVC JQGRID 增删改查 实例
JqGrid 表格控件,支持树形结构,动态加载数据,可配置添加页面、修改页面; MCV版
jqGrid表格数据展示插件,可以做出很多很炫酷的效果,你值得拥有
jqGrid是基于jquery的一个表格插件,demo中可自适应窗口大小,且单元格数据较多时,可单行显示
jqgrid加载本地数据并且分页例子,下载直接搭环境使用
; charset=utf-8"> <title>Insert title here ...<link type="text/css" rel="stylesheet" href="css/ui.jqgrid.css"> <script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script> ...
下面我们将逐步讲解怎么在MVC模式下将MongoDB数据读取,并展示在前台Jqgrid表格上。这个“简易系统”的基本设计思想是这样的:我们在视图层展示表格,Jqgrid相关Js逻辑全部放在一个Js文件中,控制层实现了“增删查改...
下面可以获取选择一行的id,如果你选择多行,那下面的id是最后选择的行的id: ...如果想获取选择的行的数据,只要传入rowId即可,如下: var rowData = $(“#gridTable”).jqGrid(‘getRowData',rowId);
jqGrid是一个非常好用的免费开源Grid组件,功能强大,适用于各种表格操作,数据管理。作为jquery插件,jqGrid使用方便,简介,美观。
MVC+Jqgrid+存储过程 全部代码
本Demo利用Jquery的jqgrid插件利用本地资源数据,实现分页。
struts1-hibernate-spring框架中jqgrid页面生成详细步骤
Lib.AspNetCore.Mvc.JqGrid.DataAnnotations-自定义数据注释,当使用强类型帮助程序时,该注释允许提供其他元数据。 Lib.AspNetCore.Mvc.JqGrid.Helper-强类型的帮助器。入门所有软件包都可以在。 您可以通过安装...
前端页面点击导出jqgrid表格为excel表格代码,有表格样式设置的代码,可以参考一下,这是我刚开始工作的时候写的,希望可以帮助像我一样的菜鸟。
JqGrid 小例子 vs2010+mvc,JqGrid 小例子 vs2010+mvc,JqGrid 小例子 vs2010+mvc
1、jqGrid中文说明,对jQgrid表格关键使用方法中文说明 2、列举了添加、删除等一些功能代码,进行说明,详细介绍了展现jQgrid表格的方法