下面是整个整合测试的代码:

ajax01.html

TestController

web.xml

springmvc.xml

applicationContext.xml

<!DOCTYPE html>
<html>
  <head>
    <title>index.html</title>

    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=gb2312">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<script type="text/javascript" charset="UTF-8">

var param = "ajaxget";
var xmlHttpRequest = null;//作为全局变量,否则在回调函数中报notdefined
function ajaxSubmit(){
if(window.ActiveXObject){
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttpRequest = new XMLHttpRequest();
}

if(xmlHttpRequest != null){
//document.write("xxx");
xmlHttpRequest.open("GET", "./testAjax?param="+param, true);
xmlHttpRequest.onreadystatechange = ajaxCallBack;//没有括号
xmlHttpRequest.send(null);
}
}

function ajaxCallBack(){
if(xmlHttpRequest.readyState == 4){
if(xmlHttpRequest.status == 200){
var responseText = xmlHttpRequest.responseText;//没有括号
document.getElementById("div1").innerHTML = responseText;//innerHTML没有括号
}
}
}

</script>
  </head>
  
  <body>
 
  <input type="button" value="check" id="check" onclick="ajaxSubmit();">
<br>
<div id="div1"></div>

  </body>
</html>
package priv.lirenhe.js.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TestController {
public TestController() {
System.out.println("------TestController------");
}
@RequestMapping(value="/testAjax",method=RequestMethod.GET)
public void testAjax(HttpServletRequest req,HttpServletResponse resp){
System.out.println("testAjax");
String param = null;
param = req.getParameter("param");
System.out.println(param);
PrintWriter pw = null;
try {
pw = resp.getWriter();
pw.print(param);
} catch (IOException e) {
e.printStackTrace();
}finally{
pw.flush();
pw.close();
System.out.println("finally");
}
}
}

web.xml配置:注意不要使用<web:xxx>的标签

<?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" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>js_001</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
  <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>
</web-app>

springmvc.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<!-- 必须有带mvc的 -->
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="priv.lirenhe.js.*"></context:component-scan>
<mvc:annotation-driven />
<mvc:resources location="/" mapping="/**"/>
<bean id="modelAndView" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<constructor-arg name="prefix" value="/"/>
<constructor-arg name="suffix" value=".html"/>
</bean>
</beans>
<!-- 
包扫描器
注解驱动
静态资源
前缀后缀
 -->

applicationContext.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

</beans>

 


如果不能加载的话就是web.xml配置的问题。


springmvc+ajax——第一讲(搭建)的更多相关文章

  1. springmvc+ajax——第二讲(页面缓存)

    springmvc+ajax+页面缓存(参考:https://www.cnblogs.com/liuling/archive/2013/07/25/2013-7-25-01.html) 必须设置响应头 ...

  2. bootstrap+Ajax+SSM(maven搭建)实现增删改查

    https://www.jianshu.com/p/d76316b48e3e 源码: https://github.com/Ching-Lee/crud 功能点: 分页 数据校验 ajax Rest风 ...

  3. SpringMVC+Ajax实现文件批量上传和下载功能实例代码

    需求: 文件批量上传,支持断点续传. 文件批量下载,支持断点续传. 使用JS能够实现批量下载,能够提供接口从指定url中下载文件并保存在本地指定路径中. 服务器不需要打包. 支持大文件断点下载.比如下 ...

  4. 《ArcGIS Engine+C#实例开发教程》第一讲桌面GIS应用程序框架的建立

    原文:<ArcGIS Engine+C#实例开发教程>第一讲桌面GIS应用程序框架的建立 摘要:本讲主要是使用MapControl.PageLayoutControl.ToolbarCon ...

  5. 框架原理第一讲,熟悉常用的设计方式.(以MFC框架讲解)

    框架原理第一讲,熟悉常用的设计方式.(以MFC框架讲解) 一丶什么是框架,以及框架的作用 什么是框架? 框架,简而言之就是把东西封装好了,使用框架开发可以快速开发程序,例如MFC程序的双击写代码. 为 ...

  6. 【AaronYang第一讲】ASP.NET MVC企业开发的基本环境[资源服务器概念]

    学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang  茗洋  EasyUI1.3.4   ASP.NET MVC 3 本篇博客地址:http://ww ...

  7. SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)

    1. 前言 最近在写毕设过程中,重新梳理了一遍SSM框架,特此记录一下. 附上源码:https://gitee.com/niceyoo/jeenotes-ssm 2. 概述 在写代码之前我们先了解一下 ...

  8. SpringMVC笔记——SSM框架搭建简单实例

    落叶枫桥 博客园 首页 新随笔 联系 订阅 管理 SpringMVC笔记——SSM框架搭建简单实例 简介 Spring+SpringMVC+MyBatis框架(SSM)是比较热门的中小型企业级项目开发 ...

  9. Spring+SpringMvc+Mybatis框架集成搭建教程

    一.背景 最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis , 以下简称SSM)框架的搭建的经历,所以在自己搭建SSM框架集成的时候,出现了这样或者那样的问题,很是苦恼 ...

随机推荐

  1. Uva 11178 Morley定理

    题意: 给你三角形三个点, 定理是 三个内角的三等分线相交得出 DEF三点, 三角新 DFE是等边三角形 然后要你输出 D E F 的坐标 思路 : 求出三个内角,对于D 相当于 BC向量逆时针旋转, ...

  2. 深度解析SpringMvc实现原理手写SpringMvc框架

    http://www.toutiao.com/a6340568603607171329/?tt_from=mobile_qq&utm_campaign=client_share&app ...

  3. CDH运维

    1.单个节点宕机后,想可能存在的问题: 时间同步是否正常运行 hbase对时间是否同步很敏感 2.zookeeper报警 ZooKeeper 服务 canary 因未知原因失败. 该警报是在重启CM的 ...

  4. 对象的宽度、top位置,x坐标属性

    DOM对象   DOM对象属性 对应css 说明 读/写 width   obj.clientWidth=20 1. 内联样式 <p style="width:20px"&g ...

  5. SQLAchemy基础知识

    一.什么是SQLAchemy? SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据 ...

  6. WPA2-PSK无线密码破解

    无线网络WIFI(wireless Fidelity )正确发音 /wai fai/ 是一个建立在IEEE 802.11标准的无线局域网,目前主流的无线上网模式主要有两种分别是 GRPS(手机无线上网 ...

  7. cf1144G 将串分解成单调递增和递减子串(贪心)

    这算哪门子dp.. 具体做法就是贪心,建立两个vector存递增序列递减序列,操作过程中a可以合法地匀一个给b 就是判断第i个数放在递增序列里还是放在递减序列里,需要根据后面的数来进行决策 #incl ...

  8. python接口自动化测试三十三:获取时间戳(10位和13位)

    很多时候,在调用接口时,需要对请求进行签名.需要用到unix时间戳. 在python里,在网上介绍的很多方法,得到的时间戳是10位.而java里默认是13位(milliseconds,毫秒级的). 下 ...

  9. mysql 去除重复 Select中DISTINCT关键字的用法 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值。其原因是 distinct只能返回它的目标字段,而无法返回其它字段,这个问题让我困扰了很久,用distinct不能解决的话,

      在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记 ...

  10. IDEA部署项目和多余的项目删掉的演示