zoukankan      html  css  js  c++  java
  • spring mvc ajax

    <%@ page contentType="text/html;charset=UTF-8" %>
    <%@ include file="/WEB-INF/views/include/taglib.jsp"%>
    <html>
    <head>
    <script type="text/javascript" src="${ctxStatic}/jquery/jquery-1.9.1.min.js"></script>
    <title>Insert title here</title>
    <script type="text/javascript">
        function ajaxTest(){
            $.ajax({
            data:"name="+$("#name").val(),
            type:"GET",
            dataType: 'json',
            url:"${ctx}/user/logindo.do",
            error:function(data){
                //alert("出错了!!:"+data.msg);
                $("#result").html("出错了!!:"+data.msg) ;
            },
            success:function(data){
                //alert("success:"+data.msg);
                $("#result").html(data.msg) ;
            }
            });
        }
    </script>
    </head>
    <body>
        <input type="text" name="name" id="name"/>
        <input type="submit" value="登录" onclick="ajaxTest();"/>
        <div id="result"></div>
    </body>
    </html>

    controller

    package com.thinkgem.jeesite.modules.test.web;
    
    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("${adminPath}/user")
    public class LoginssController {
        @RequestMapping(value="logindo.do")
        public @ResponseBody Map<String,Object> login(HttpServletRequest request,HttpServletResponse response) throws IOException{
            System.out.println(request.getParameter("name"));
            String name = request.getParameter("name");
            
            Map<String,Object> map = new HashMap<String,Object>();
            if(name == null) return map;
            if(request.getParameter("name").equals("123")){
                System.out.println("城东");
                map.put("msg", "成功");
            }else{
                System.out.println("失败");
                map.put("msg", "失败");
            }
            return map;
        }
        
        @RequestMapping(value="loginss.do")
        public String aaa()    {
            return "modules/test/aaa";
        }
    }
  • 相关阅读:
    /usr/bin/ld: 找不到 /usr/lib64/libatomic.so.1.0.0
    linux Version mismatch error. This is libtool 2.4.6 Debian-2.4.6-2
    java播放语音文件
    java冒泡排序
    java递归求和
    常见芯片标号说明
    keil5 新建 stm32项目 步骤
    st-link 升级固件时报错“is not in the DFU mode”
    数码管 段选位选
    C51 定时器
  • 原文地址:https://www.cnblogs.com/yasepix/p/5662889.html
Copyright © 2011-2022 走看看