Flask接口签名sign原理与实例代码浅析
208
2023-06-15
spring mvc 和ajax异步交互完整实例代码
spring MVC 异步交互demo:
1.jsp页面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
2.controller:
package xm.zjl.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.ResponseBody;
/**
* 登录controller
*
* @author Administrator
*
*/
@Controller
@RequestMapping("/user/*")
public class LoginController {
@RequestMapping(value="login.do")
public @ResponseBody Map
System.out.println(request.getParameter("name"));
Map
if(request.getParameter("name").equals("123")){
System.out.println("城东");
map.put("msg", "成功");
}else{
System.out.println("失败");
map.put("msg", "失败");
}
return map;
}
}
3.pom文件:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> &lhttp://t;groupId>com.fasterxml.jackson.core QTgGuFJXRW
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
&lhttp://t;groupId>com.fasterxml.jackson.core
QTgGuFJXRW
这里注意如果相关json包没有添加到pom.xml文件中会报:406 not acceptable
4.spring-servlet.xml文件:
xmlns:context="http://springframework.org/schema/context" xmlns:p="http://springframework.org/schema/p" xmlns:mvc="http://springframework.org/schema/mvc" xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-3.0.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-3.0.xsd">
xmlns:context="http://springframework.org/schema/context"
xmlns:p="http://springframework.org/schema/p"
xmlns:mvc="http://springframework.org/schema/mvc"
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://springframework.org/schema/beans
http://springframework.org/schema/beans/spring-beans-3.0.xsd
http://springframework.org/schema/context
http://springframework.org/schema/context/spring-context.xsd
http://springframework.org/schema/mvc
http://springframework.org/schema/mvc/spring-mvc-3.0.xsd">
5.web.xml文件:
xmlns:xsi="http://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_3_0.xsd" id="WebApp_ID" version="3.0">
xmlns:xsi="http://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_3_0.xsd"
id="WebApp_ID"
version="3.0">
这里需要注意的是:
如果写成:
会提示:$ is not defined错误
记录一下
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~